简体   繁体   中英

Is there any reason NOT to set HTML encoding to UTF-8?

Is there any good reason NOT to use UTF-8 as an encoding in day to day development?

IE: Does using the following tag in <head>...</head> come with any downsides?

<meta charset="utf-8">

Is there any good reason NOT to use UTF-8 as an encoding in day to day development?

Not really. There are niches that don't play so well with UTF-8, like old Japanese webmail services, and some dodgy text editors that still prefer the Windows ANSI code page, but they're slowly going away and most people can ignore them.

There are a few legal blips like Chinese software products having to support nasty old GB18030, but that doesn't preclude UTF-8 support, or affect web sites as I understand it.

Though other encodings can work out smaller that UTF-8, there's not usually enough of a difference to care—or to offset the loss of the rest of the Unicode repertoire. UTF-16 can still cover everything, and could in theory be smaller for non-ASCII BMP text... but for HTML that is invariably drowned out by the extra length of all the ASCII text including tags and whitespace. Plus UTF-16 doesn't work well on the web.

In any case you'll hopefully be serving your pages compressed, which will make even that small difference close to void.

<meta charset="utf-8">

Is the fancy modern way of saying it but for wider support in older browsers I would still go for:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

As this hints, what you're actually doing is pretending an HTTP header was sent with the charset in. So you will also need to make sure there's not a real HTTP Content-Type...charset parameter, because the real header's parameter trumps the HTML 'meta'-hack. The Apache AddDefaultCharset directive is sometimes unwisely used to give you a charset you might not want.

It really comes down to the characters you are displaying on the page.

Here's a good article by SO co-founder Joel S: http://www.joelonsoftware.com/articles/Unicode.html

It doesnt really matter as it will be ignored most of the time, generally the HTTP Content-Type header will be used instead. I also think it will be ignored in older browsers.

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