encoding should be set before setting scriptencoding