简体   繁体   English

有没有理由不将HTML编码设置为UTF-8?

[英]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? 有没有什么好的理由不在日常开发中使用UTF-8作为编码?

IE: Does using the following tag in <head>...</head> come with any downsides? IE:在<head>...</head>使用以下标记是否有任何缺点?

<meta charset="utf-8">

Is there any good reason NOT to use UTF-8 as an encoding in day to day development? 有没有什么好的理由不在日常开发中使用UTF-8作为编码?

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. UTF-8和日本的旧网络邮件服务以及一些仍然偏爱Windows ANSI代码页的狡猾的文本编辑器都有不太好的利基,但它们正在慢慢消失,大多数人都可以忽略它们。

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. 像中国软件产品一样,有一些法律问题不得不支持令人讨厌的旧版GB18030,但这并不排除UTF-8支持,也不会影响我理解的网站。

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-8更小,但通常没有足够的差别来照顾或抵消其余Unicode曲目的丢失。 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. UTF-16仍然可以涵盖所有内容,理论上对于非ASCII BMP文本来说可能更小......但对于HTML来说,总是被包括标签和空格在内的所有ASCII文本的额外长度所淹没。 Plus UTF-16 doesn't work well on the web. 另外,UTF-16在网络上运行不佳。

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. 正如这提示的那样,你实际在做的是伪装一个带有charset的HTTP头。所以你还需要确保没有真正的 HTTP Content-Type ... charset参数,因为真正的头部参数胜过HTML'meta'-hack。 The Apache AddDefaultCharset directive is sometimes unwisely used to give you a charset you might not want. Apache AddDefaultCharset指令有时不明智地用于为您提供您可能不需要的charset

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 这是SO联合创始人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. 它并不重要,因为它在大多数情况下会被忽略,通常会使用HTTP Content-Type标头。 I also think it will be ignored in older browsers. 我也认为在旧版浏览器中会被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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