Character encoding for .js files

hankknight used Ask the Experts™

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


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


Or could that  cause bugs?

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