views:

51

answers:

3

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?

A: 

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.

flaab
Hey Flaab, thanks for the response. I know both will work, but this is an efficiency and compatibility question really. It seems the header() function is far more efficient
Hamish
+3  A: 

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.

Peter Bagnall
Thanks for the response Peter. Yes, the header does override the meta tag (http://www.w3.org/International/questions/qa-html-encoding-declarations#httpheadwhat), but it still seems strange that the meta tag could cause such a delay when it is the first thing declared. I don't see any reason to keep the meta tag, although lots say to do so (in case headers are stripped).
Hamish
A: 

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.

netrox
Thanks Netrox, i agree. That's not an issue for me though, so i'd prefer the 30% increase in speed than to take care of people saving my pages!
Hamish