简体   繁体   中英

Content type vs HTML encoding

I'm bulding a site and I've set its content type to use charset UTF-8. I'm also using HTML encoding for the special characters, ie: instead of having á I've got á .

Now I wonder (still bulding the site) if it was really necesary to do both things. Looking for the answer I found this:

http://www.w3.org/International/questions/qa-escapes.en.php

It says that I shoud not use HTML encoding for any special characters but for > , < and & . But the reason is that escapes

can make it difficult to read and maintain source code, and can also significantly increase file size.

I think that's true but very poor argument. Is it really THE SAME thing using the escapes and the special characters?

The article is in fact correct. If you have proper UTF-8 encoded data, there is no reason to use HTML entities for special characters on normal web pages any more.

I say "on normal web pages", because there are highly exotic borderline scenarios where using entities is still the safest bet (eg when serving JavaScript code to an external page with unknown encoding). But for serving pages to a browser, this doesn't apply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM