开发者

UTF-8 content type meta tag is slowing down the page loading, why?

开发者 https://www.devze.com 2023-01-18 03:04 出处:网络
I\'m setting the following meta tag to set the content type and in doing so the page load time jumps by about 30% (350 --> 500 msec using chrome dev tools and firefox firebug). Note: I have it placed

I'm setting the following meta tag to set the content type and in doing so the page load time jumps by about 30% (350 --> 500 msec using chrome dev tools and firefox firebug). Note: I have it placed first thing inside the tag to prevent re-rendering of page content. Also, the size of the page in kb is essentially the same, so that is not the issue.

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

If i don't include the tag, chars don't render properly. If i remove it and instead add the header to my PHP as per below, everything is fast again.

header('Content-Type: text/html; charset=utf-8');

So my first question is, do i actually need the meta tag or is the header enough for all browsers? I've heard i need the meta tag so forms work properly, but it seems the header may be good enough.

My second question is, why开发者_运维问答 on earth should this tag affect the load time, that just seems plain crazy?


The header will override the meta tag I believe. So you should use the header, not the meta tag. The problem with the meta tag is that the browser starts to parse the HTML before it even sees the meta tag. Once it encounters the meta tag it now knows the encoding, so it has to start again. That may explain the delay you're seeing.


That maybe depends of the code you are executing afterwards. That itself should not affect. If that is a webpage itself, you don't need to execute the header() function, the html meta tag will suffice.


There's a potential problem with not using the meta tag. Once it's outputted and you save it locally, it won't know which language is being used. By setting it in HTML meta, it lets the browser know which language to use. Otherwise you'd get garbled characters if you're using Asian characters. If you're using just English, then it won't be much of an issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号