homeSoftware tutorialHow do browsers get CSS document encoding?
How do browsers get CSS document encoding?

It is much more complicated for the browser to obtain the CSS document code than the HTML document code. It can set the code in the content type field of the reponseheader, the link tag can set the charset attribute, the CSS document can also set the code, and finally there is a default coded document.

influence

What impact will CSS documents have if they are coded incorrectly? English characters can be recognized as a whole, but Chinese characters will be displayed as garbled code. This is mainly in Chinese font. The Chinese font displayed on the page is English font (the content is still Chinese, I mean the displayed font changes).

What is the order in which browsers get CSS document encoding?

According to [1]? For the description of CSS 2.1 specification, the coding of an external CSS file shall be determined according to the following priority:

1. The encoding specified by the "charset" parameter of the "content type" field in the HTTP response header. 2. Codes defined by BOM and / or @ charset. three<link charset="">Or metadata provided by other linking mechanisms, if any. 4. Introduce the HTML of the CSS file or the code determined in another CSS file (if any). 5. If the code cannot be determined in the above steps, it is assumed to be UTF-8.


Send a method to get the code from BOM (c#):

///< summary > / / / judge the encoding from the byte stream (if NULL is returned, the encoding cannot be judged) / / < / summary > / / < param name = "BT" > input byte stream < / param > / / < returns > < / returns > internal static string getencodingbyte (byte \ [\] BT) {/ / UTF-8 var utf8 with BOM = new byte \ [\] {0xef, 0xbb, 0xbf}; if (bt\[0\] == utf8\[0\] && bt\[1\] == utf8\[1\] && bt\[2\] == utf8\[2\])        {                return "utf-8";        }        // UTF-32-BE        var utf32Be = new byte\[\] { 0x00, 0x00, 0xFE, 0xFF };         if (bt\[0\] == utf32Be\[0\] &&                bt\[1\] == utf32Be\[1\] &&                bt\[2\] == utf32Be\[2\] &&                bt\[3\] == utf32Be\[3\])        {                return "utf-32";        }        // UTF-32-LE        var utf32Le = new byte\[\] { 0xFF, 0xFE, 0x00, 0x00 };         if (bt\[0\] == utf32Le\[0\] &&                bt\[1\] == utf32Le\[1\] &&                bt\[2\] == utf32Le\[2\] &&                bt\[3\] == utf32Le\[3\])        {                return "utf-32";        }        // UTF-32-2143        var utf322143 = new byte\[\] { 0x00, 0x00, 0xFF, 0xFE };         if (bt\[0\] == utf322143\[0\] &&                bt\[1\] == utf322143\[1\] &&                bt\[2\] == utf322143\[2\] &&                bt\[3\] == utf322143\[3\])        {                return "utf-32";        }        // UTF-32-3412        var utf323412 = new byte\[\] { 0xFE, 0xFF, 0x00, 0x00 };         if (bt\[0\] == utf323412\[0\] &&                bt\[1\] == utf323412\[1\] &&                bt\[2\] == utf323412\[2\] &&                bt\[3\] == utf323412\[3\])        {                return "utf-32";        }        // UTF-16-BE        var utf16Be = new byte\[\] { 0xFE, 0xFF };         if (bt\[0\] == utf16Be\[0\] &&                bt\[1\] == utf16Be\[1\])        {                return "utf-16";        }        // UTF-16-LE        var utf16Le = new byte\[\] { 0xFF, 0xFE };         if (bt\[0\] == utf16Le\[0\] &&                bt\[1\] == utf16Le\[1\])        {                return "utf-16";        }         return null;}
Software application: front end template download; Development design; SEO optimization; Browse the web offline. Note: this software is not a hacker program and cannot download background data!
Disclaimer: the service is used for personal learning, research or appreciation, as well as other non-commercial or non-profit purposes. However, it shall comply with the provisions of copyright law and other relevant laws, and shall not infringe the legitimate rights of this website and relevant obligees. The risks arising from the use of tools on this website have nothing to do with this software.
Copyright © 2019-2021 all rights reservedYue ICP Bei No. 19111427-2
News Doc Website topics