Question

I do not have the link anymore as it was a few months back, but there was a great and detailed article about setting the charset of the body being sent to the user-agent.

The gist of the article was that when possible, send it via the content-type header since the user-agents parser will know before the body begins being parsed that it is (for example) utf-8, etc.

Sending it via meta tag means it has to wait for said meta tag to be found, then return to the top of document and begin reparsing the document again.

So for quite a while now, we have been sending the charset via content-type header, like so (in PHP anyways):

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

All works great. As far as we can see everything is as should be in all the commonly used user-agents.

My question is this, as a backup / fail-safe / just in case, should we still send the charset meta tag? Will sending it again using the meta tag defeat the purpose of sending it via the content-type header?


edit: This is not the exact article, but re-iterates the point ( http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyCharsetEarly ) that when possible, send charset via header.

Était-ce utile?

La solution

Yes, I always try to do this since it makes the document more portable. E.g. It will display the same way when viewing from a local file, as it does when delivered via a web server.

Autres conseils

my question is this, as a backup / failsafe / just incase, should we still send the charset meta tag?

Yes, it is always good practice to provide a meta tag in your markup which specifies the encoding. It should be the first tag after the <head>.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top