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

anand bhoraniya picture anand bhoraniya · Apr 27, 2013 · Viewed 14.6k times · Source

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

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

Answer

S&#233;bastien Renauld picture Sébastien Renauld · Apr 27, 2013

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.