Suppose a browser encounters a <meta>
tag that specifies the character-encoding, like this:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Does it start over from the beginning parsing the page again, since some of the preceding characters in the <head>
section may have been interpreted incorrectly? Or are there some other constraints that prevent prior characters from being interpreted incorrectly?
As far as I know, browsers wont go back after finding a charset declaration in the <head>
and they assume a ASCII compatible charset up to that point. Unfortunately I can't find a reference to confirm this.
Confirming browsers will ignore a Content-Type meta element, if the server already provides a Content-Type HTTP header, so you can't override a "wrong" server-side charset with a <meta>
element.
The point for the <meta>
charset declaration is for HTML documents that are not server by a HTTP server.
That means you shouldn't rely on a <meta>
charset declaration in the HTML file, but configure your HTTP server to provide the correct charset. If for some reason you have to rely on a <meta>
charset declaration, you should only have ASCII characters up to that point and position it as early in the <head>
as possible, preferably as the first element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With