PageSpeed : Avoid a characterset in the "Meta tag"

Published

What is a character set?

In simple, character set is the set of characters that you can use in webpage.

I should specify charset , but not in meta tag? Why and how can I specify character set then?

It is better to specify a Character set. and it can be set via two primary methods, with meta tags or with headers.

Google dev tools suggest to remove meta tags wherever possible because it will affect information duplication.
and most web servers automatically send content type headers along with the content that is being requested to be downloaded.
And if they already send a Content type header, and if we specify our own, it will be confusing for the browser.



Solution / Recommendation


It is very clear that "We should specify a charctetr set" and it must't be set via a meta tag.
So always prefer "Headers" over <meta> tags.

Remove if you find charset meta tag in your documents and use any of methods below.

Method one : Using PHP


If you are generating your content using PHP, put below lines at the top of pages.

<?php
header ("content-type:text/htmll; charset=utf-8")
?>

Method Two : Using .htaccess

If you are using Apache, it will be better to specify character set for web documents using .htaccess

Add below line inside your .htaccess file.

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

Method Three : Using nginx

more-set_headers -t 'text/html' 'content-type:text/html'charset=utf-8';


Comments

Post a Comment