Specify a character set early

Updated on Mar 13, 2019

Method Type: User (content)
(this means that the method is handled by the webmaster)

Status: Must be applied by the user.

Introduction:

A character set is the number representation of text characters. Systems that utilize character set like UTF-8 are character encodings. UTF-8 can encode all possible characters in Unicode standard and is the dominating character encoding for the World Wide Web. Using a different character type than the original in which the file was encoded can cause an incorrect render of the page.

How "specifying a character set early" works:

When a user opens a page, he requests information about the page from the web server via the web browser. Without specifying the character set the browser has to find it on his own before it can start parsing page elements which will add a delay in the page load time.

Specifying a character set early provides the following Advantages:

Reduces page load time

How to specify character set early in the HTTP response:

The best way to specify a character set early in the HTTP response is to do so in the .htaccess file. You will need to add the following line to your .htaccess file:

AddCharset UTF-8 .html

In this example we have added a new character set (UTF-8) for all HTML files. This will add a Content-Type header which will look like this:

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

You can also manually add a Content-Type header using:

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

If you are using different character types for some files you can specify that in the .htaccess file:

<Files "special.html">
AddCharset UTF-8 .html
</Files>

With this, only the file "special.html" will be using the UTF-8 character type. If let's say all other files use the ISO-8859-1. UTF-8 is build with a backward compatibility to ASCII so files initially encoded with that character type can be opened via UTF-8.

On this page...

    Optimized SSD Web Hosting

    • Free Domain Transfer
    • Google PageSpeed Enabled
    • 24/7 Technical Support
    • Fast SSD Storage
    • Hack-free Protection
    • Free Cloudflare CDN
    • Immediate Activation
    View More