Character encoding for .js files

hankknight
hankknight used Ask the Experts™
on
Hello,

This is in the header sent by my server for all .js files:

Content-Type:·application/x-javascript(CR)(LF)

Can I encode my .js files in UTF-8 then send this header?

Content-Type:·application/x-javascript;·charset=UTF-8(CR)(LF)

Or could that  cause bugs?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Javascript internally works with all text in Unicode, so there shouldn't be a problem.  Where you're using Javascript to pass data on to server-side scripts, you should be careful to use encodeURIComponent() and encodeURI().

The encodeURI() function encodes entire URIs  so it leaves characters such as :?& intact. encodeURIComponent() encodes strings to be individual parameters of a URI, so it encodes all characters except ~!*().

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial