google-website-optimizer

Avoid a character set in the meta tag AND Specify a character set


I have alredy add code in my php web page like...

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

than after in https://developers.google.com/speed suggest for


Solution

  • Use a HTTP header rather than a meta tag. Implementing that depends on what server-side tech you are using.

    If you are generating your content using PHP, put this at the top of your page:

    header("Content-Type: text/html; charset=utf-8");
    

    If you are using any other server-side programming language, there must be a similar option.

    Alternatively, if you are using Apache, you can do it using htaccess directives as follows:

    AddType 'text/html; charset=UTF-8' html
    

    And if you're using nginx, put this in your config:

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

    More on the meta tag "avoidance"

    Google dev tools suggest removing meta tags wherever possible due to the information duplication that it may cause. Some webservers automatically send content-type headers, for example, and in some cases, incoherent meta tags can cause browsers to get... shall we say, confused.

    To avoid duplication of information and possible charset-related headaches, always prefer headers over meta tags.