Most developers (myself included) are often unaware of the performance impact of the Content-Type / charset of a web page. Ideally you should set this as an HTTP Header vs. using META http-equiv
. It’s often though that this only helps with the transport and display of data, however, the browser also makes use of it when parsing CSS & JS assets. Tags related to those provide an optional ‘charset
‘ attribute should they ever need to vary from your content.
General guidance is to set this at the very top of the <head>
before <title>
; and within the first 1024 bytes, though there are reports that Firefox will look at the first 2048 bytes of the page for this META
information.
Not doing so may cause the browser to do a codepage restart to re-parse assets that were interpreted in the potentially incorrect codepage.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
REFERENCES:
- http://gtmetrix.com/specify-a-character-set-early.html
- http://www.kylescholz.com/blog/2010/01/performance_implications_of_charset.html
- http://zoompf.com/2009/12/browser-performance-issues-with-charsets
- http://blogs.msdn.com/b/ieinternals/archive/2011/07/18/optimal-html-head-ordering-to-avoid-parser-restarts-redownloads-and-improve-performance.aspx