Analysis of the causes of accidents caused by Unicode signature BOM

Analysis of the causes of accidents caused by Unicode signature BOM
Maybe you are using include files here, which is usually done for headers and footers. When I opened the included file, I found that the item "Include Unicode Signature BOM" in the page properties was checked. Then I tell you that the accident was caused by this BOM.

unicode-bom

Today, I encountered another BOM accident when writing a JS script.
I inserted an external JS into the page, and inside it there was this sentence: $.getJSON("/my/newmsg", function(data){alert(data);}); Other browsers could pop up the content normally, but IE did not. I was depressed for nearly an hour. I suspected that this sentence was written incorrectly, that the JSON data format was wrong, and that I had a problem with my character...
Later, I suspected that the encoding was wrong, so I saw the damn BOM checked. As soon as I removed it, the miracle emerged from under the dark cloud.
Although I am lazy and rarely update my blog, I have to come up and record this incident because it is really unexpected. JS can also cause accidents due to BOM – -|

There is a concept of BOM in the Unicode specification.
BOM is the abbreviation of Byte Order Mark, which is a byte order mark. This thing cannot be seen in an ordinary text editor. Can it be said to be a file header? Can it only be seen in a binary editor? That may be the case.
In UCS encoding, there is a character called "ZERO WIDTH NO-BREAK SPACE", and its encoding is FEFF. FFFE is a character that does not exist in UCS, so it should not appear in actual transmission. The UCS specification recommends that we transmit the character "ZERO WIDTH NO-BREAK SPACE" before transmitting the byte stream. In this way, if the receiver receives FEFF, it means that the byte stream is Big-Endian; if it receives FFFE, it means that the byte stream is Little-Endian. Therefore, the characters "ZERO WIDTH NO-BREAK SPACE" are also called BOM.
UTF-8 does not require BOM to indicate byte order, but can use BOM to indicate encoding. The UTF-8 encoding of the characters "ZERO WIDTH NO-BREAK SPACE" is EF BB BF. So if the receiver receives a byte stream starting with EF BB BF, it knows that it is UTF-8 encoded. Windows uses BOM to mark the encoding of text files.

<<:  How to use partitioning to optimize MySQL data processing for billions of data

>>:  The process of setting up an environment for integration testing using remote Docker

Blog    

Recommend

Detailed explanation of the use of base tag in HTML

In requireJS, there is a property called baseURL....

Complete code for implementing the vue backtop component

Effect: Code: <template> <div class=&quo...

Timeline implementation method based on ccs3

In web projects we often use the timeline control...

Solve the 1251 error when establishing a connection between mysql and navicat

I reinstalled the computer and installed the late...

How to create a view in MySQL

Basic syntax You can create a view using the CREA...

Summary of the differences between Vue's watch, computed, and methods

Table of contents 1 Introduction 2 Basic usage 2....

Share 10 of the latest web front-end frameworks (translation)

In the world of web development, frameworks are ve...

Method to detect whether ip and port are connectable

Windows cmd telnet format: telnet ip port case: t...

How to detect if the current browser is a headless browser with JavaScript

Table of contents What is a headless browser? Why...

Detailed explanation of the principle of Docker image layering

Base image The base image has two meanings: Does ...

Enable sshd operation in docker

First, install openssh-server in docker. After th...