Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Javascript files include the BOM or not?

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.

like image 796
Andrew Theken Avatar asked Mar 27 '13 21:03

Andrew Theken


People also ask

Should I use BOM?

BOM use is optional. Its presence interferes with the use of UTF-8 by software that does not expect non-ASCII bytes at the start of a file but that could otherwise handle the text stream.

Does UTF-8 need BOM?

In the UTF-8 encoding, the presence of the BOM is not essential because, unlike the UTF-16 or UTF-32 encodings, there is no alternative sequence of bytes in a character. The BOM may still occur in UTF-8 encoding text, however, either as a by-product of an encoding conversion or because it was added by an editor.

How do I save a file without BOM?

Open the file you want to verify/fix in Notepad++ In the top menu select Encoding > Convert to UTF-8 (option without BOM) Save the file.

What is BOM in file?

A byte order mark (BOM) is a sequence of bytes used to indicate Unicode encoding of a text file. The underlying character code, U+FEFF , takes one of the following forms depending on the character encoding. Bytes. Encoding Form. EF BB BF.


1 Answers

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"

like image 172
Rich Wagenknecht Avatar answered Oct 20 '22 09:10

Rich Wagenknecht