I am reading the FAQ section in this forum and I have seen this:
Can I set the MIME type with a <meta/> tag?
No. A user agent needs to know the content type before it starts parsing the response body. When it encounters an element like this, it's already too late:
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
The MIME type must be sent as a Content-Type HTTP header. The character encoding should be specified in the XML declaration (see above).
Nevertheless, if I open the code of this same forum, I find this meta:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
Can anyone explain it to me please?
Thanks very much.
We do that to set the charset only. The MIME type in that line is indeed ignored, but the charset is not. HTML5 has officially allowed us to shorten that line to only the parts that matter:
The meta tags are often read IF the server did not send an appropriate header.
The meta tag setting the charset is also ignored if the server sent a different one.
If neither server headers nor meta tags for something are present, the user agent (browser) gets to guess, or use some internally-selected default. IE6 used to use heuristics to guess the charset of a page, after which it would then start re-rendering the page all over again.
It's considered good practice to have a charset meta tag as a backup anyway, even though stuff like the UTF-7 hack are very very unlikely : )