Web page Front-End Analysis: About Taobao page coding puzzle

Source: Internet
Author: User
Tags character set reference

Because is about to start Taobao project, in front of the inevitable to in-depth understanding of Taobao ued norms, norms or relatively full, Just for the taobao.com encoding and character set of choice there are a lot of confusion, because of historical reasons, Taobao page encoding is ASCII encoding, character set using gb2312, this is not improper, the trouble is to do code development time to take out the energy to deal with complex and diverse character sets, such as the Taobao home page is asci I, the page in the meta of the specified character set is GB18030, but under window, with Firefox save the page to local, found that the Meta field of the character set into gb2312, and in IE open Taobao home page, the browser that the character set is gb2312, But the GB18030 itself is larger than the gb2312, so in the event of a cross-border character, the browser will also use the GB18030 character set to interpret the page.



In pure HTML, the pitfalls of this same coded character set are often hack by increasingly powerful A-level browsers, so as long as the roughly compatible GB character set is used, the page probably doesn't have any exceptions. However, when an ASCII HTML is used to refer to a UTF encoded CSS or JS file, you must specify the encoding of the referenced file. But confusing is, in the Taobao home page but there is a reference to the UTF file, and not the case, such as Taobao home end of the tbra-fp.js, did not specify its code,
<script type="text/javascript" 
src="http://assets.taobaocdn.com/tbra/1.0/tbra-fp.js?
t=20090619.js"></script>

And here's tbra-fp.js is UTF8 code, fortunately this file is only English, and there is no AJAX-related code, phonemic UTF and ASCII in the English range can be combined, this file is relatively correct to work with the home page. And in the bottom of the first few of the sandbox reference several JS files are specifications of the callout charset=gb2312,
<script type="text/javascript" 
src="http://cn2.adserver.yahoo.com/a?
f=2121060025&p=cntaobao&l=TBT1&c=r" charset="gb2312"></script>

And these sandbox references JS is also really ASCII-encoded files, because JS contains Chinese characters, in order to avoid garbled code must be consistent with HTML. This kind of file coding is not uniform phenomenon in the home there are several places, probably a bug it.



We say that the GB character set is based on the expansion of ASCII, but the extent of each character set is not consistent, and different character sets may overlap phenomenon, after all, each extension is a country or region alone action, For example, gb2312 and Big5 to be able to display simplified and traditional Chinese respectively to the ASCII, and these two extensions are not compatible with the character set. In other words, a file containing simplified and traditional characters cannot use both gb2312 and Big5 to correctly display all Chinese characters at the same time. and gb2312 the number of Chinese characters are not much, so using gb2312 to deal with Chinese is a lot of hidden dangers. It can be cumbersome to encounter a mismatch between the front end and the background character set. In the Taobao home page of the source code is a lot of this situation:




Debugging the encoding and character set takes a little time and effort. If the unified use of Unicode character sets, there will probably not be a variety of coding caused by the cost of development costs and software pitfalls. Hi, this is also to do the whole station when the structure of the need to consider the matter, to do the development of the words just to follow the specification is good, but in the development of a little more careful to ensure that the file code and character set to maintain the same, without him.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.