HTML5:哪个更好-使用字符实体比直接使用字符更好? [英] HTML5: which is better - using a character entity vs using a character directly?

查看:98
本文介绍了HTML5:哪个更好-使用字符实体比直接使用字符更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近注意到很多知名网站都在其来源中直接使用字符,例如:

I've recently noticed a lot of high profile sites using characters directly in their source, eg:

<q>"Hi there"</q>

而不是:

<q>&ldquo;Hi there&rdquo;</q>

以下哪个是首选?我过去一直使用实体,但是直接使用字符似乎更具可读性,并且在Unicode文档中似乎还可以。

Which of these is preferred? I've always used entities in the past, but using the character directly seems more readable, and would seem to be OK in a Unicode document.

推荐答案

如果编码为UTF-8,则正常字符可以正常工作,没有理由不使用它们。不支持UTF-8的浏览器在显示现代网页时还会遇到很多其他问题,因此不必担心。

If the encoding is UTF-8, the normal characters will work fine, and there is no reason not to use them. Browsers that don't support UTF-8 will have lots of other issues while displaying a modern webpage, so don't worry about that.

因此它更容易实现,而且功能更多可读使用字符,我更愿意这样做。

So it is easier and more readable to use the characters and I would prefer to do so.

虽然使用压缩和缩小还有很多好处,但它也节省了几个字节。

It also saves a couple of bytes which is good, although there is much more to gain by using compression and minification.

这篇关于HTML5:哪个更好-使用字符实体比直接使用字符更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆