So you run your test on Gtmetrix and you notice a recommendation that says Avoid a character set in the meta tag and now you’re like, what the hell does that even mean?
The following resources have a character set specified in a meta tag. Specifying a character set in a meta tag disables the lookahead downloader in IE8. To improve resource download parallelization, move the character set to the HTTP Content-Type response header.
If you look at your source code, it is almost certain that you have something like this in your header.
<meta charset="UTF-8" />
Now you might be thinking, ok well I will just remove it, job done.
Well, not quite.
You see there is a good chance that you actually need it and the reason for that is there is also a very good change your running an Apache web server.
By default Apache serves files in ISO-8859-1 which is laymen terms means it cannot encode all the wonderful characters we all love to use on our modern websites.
ISO-8859-1 vs UTF-8
Wikipedia gives you a pretty good idea about what they are, however I am quite sure that most of you don’t want to go and read any of that crap.
So I will break it down and pick out the important differences.
- ISO-8859-1 is the Latin-1 (western European languages) encoding.
- The first 128 characters are the standard ASCII set which includes the Arab numerical system of (0 – 9), uppercase and lowercase English alphabet and a few special characters.
- All characters in this family are single byte.
- The upper echelons of this character set, i.e. (160 – 255), include special characters and symbols used throughout Western Europe, example – ® or Ô to name but a few.
- UTF-8 is the the mother of all Character Sets. It encompasses every Major Alphabet and many minor ones in to a single Character set.
- As with ISO-8859-1 the first 128 characters are the standard ASCII set.
- Here is where things get a little more interesting. UTF-8 is backwards compatible and can encode all ISO-8859-1 characters which are single byte. But it can also encode multi-byte characters which expands its arsenal of characters way beyond that of ISO-8859-1.
- It is used by more than half of all websites, it is also increasingly being used across other platforms such as operating systems.
- The Internet mail Consortium (IMC) recommends that you only use UTF-8 for sending mail.
So we can clearly see that UTF-8 has a clear advantage over ISO-8859-1 and I would highly recommend that you use it.
Now in order to ensure your character set is set to UTF-8 we can add a simple line to the top of .htaccess
# pass the default character set AddDefaultCharset utf-8
What this line does is simply define UTF-8 as the default character set. You can keep the meta tag variant, but by adding the above line to .htaccess we are fixing the issue with Internet Explorer 8 as well as the recommendation by Gtmetrix.