18

When testing this page with Page Speed, I get the a Specify a character set error:

The following resources have no character set specified in their HTTP headers. Specifying a character set in HTTP headers can speed up browser rendering.

The Content-Type tag is present and the page was saved with UTF-8 encoding as well, so where is the error coming from?

1
  • where in apache? which directory?
    – user16287
    Jun 15, 2012 at 11:44

1 Answer 1

19

It is referring to Response Headers and not document body ("Content-Type tag").

If you check Response Headers of your page with any HTTP Debugger (for example, Net panel of Firebug for Firefox, or similar tab of Developer Tools in Google Chrome/Internet Explorer/Safari/Opera), you will see this line:

Content-Type: text/html

At the same time, if you check the same for this page, you will see:

Content-Type: text/html; charset=utf-8

Page Speed is referring to the missing part. Having correct character set present in headers will indeed speed up rendering the page a bit. With incorrect charset specified in response header (or no character set at all) browser needs to scan/interpret the page until it find the correct character set declaration (the <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> line) and then re-start the rendering process if character set is different from browser's default setting.

The performance penalty is not big at all -- for user it is unnoticeable unless really old/slow hardware is in use (although it differs for each browser and browser version). Maybe there are some other "penalties" that are directly related to this, but I personally unaware of them.

Fixing: If you generate this header yourself (in your PHP script), then you need to alter it to include charset as well. If your script does not do such header manipulations, then it is server misconfiguration issue.

4
  • I just added header('Content-type: text/html; charset=UTF-8');. Thanks a lot!
    – Alex
    Aug 20, 2011 at 17:23
  • 6
    You can also view the response headers with curl --head $url. The default charset can be specified in Apache by adding AddDefaultCharset utf-8 to a config file like .htaccess.
    – Lri
    Mar 23, 2012 at 10:32
  • +1 for clear explanation, often wondered this and been confused. Solved with htaccess AddDefaultCharset addition
    – Malachi
    Apr 22, 2012 at 10:17
  • Shouldn't <meta charset="utf+8"> suffice?
    – user56995
    Oct 28, 2016 at 12:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.