13

I believe that most people suggest using UTF-8 as the encoding for Javascript files.

Is there a standard about whether those files include the Byte-Order Mark, or do not included it? (i.e. Should JS files be served with/without the UTF-8 BOM?)

I'd like to see an RFC, or a "de facto" standard of this, and not so much an opinion of which is preferred by individuals.

Andrew Theken
  • 3,202
  • 1
  • 26
  • 51
  • 2
    http://stackoverflow.com/a/2223926 An answer that is unspecific to JS, but might be relevant. – Jon Sykes Mar 28 '13 at 12:37
  • A related issue, here, where browsers are confused about the encoding of a javascript resource: https://stackoverflow.com/questions/52102142/why-must-i-specify-charset-attributes-for-by-script-tags – Christopher Schultz Aug 30 '18 at 17:10

1 Answers1

6

Wikipedia has a good explanation of why NOT to include a BOM with UT8.

http://en.wikipedia.org/wiki/Byte_order_mark#cite_note-3

"Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature"

Rich Wagenknecht
  • 670
  • 7
  • 13
  • @jon-sykes should get credit for referencing a similar question, and the authoritative source more directly, but I am marking this as the accepted answer, since it includes the same info. – Andrew Theken Feb 06 '14 at 12:54