Search code examples
apacheperformancefontsdrupal-8webfonts

How to specify the character set used by the page in the HTTP header for WOFF2?


I hosted the google font on my Drupal 8 site.

When I scan my site with different tool, I have this error message :

Specify a character set in your response HTTP headers No character sets are specified in the HTTP headers of the following resources. Specifying a character set speeds up the display of pages in the browser.

https://www.domaine.com/themes/custom/bootstrap_subtheme_front_office/fonts/source-sans-pro-v11-latin-700.woff2 https://www.domaine.com/themes/custom/bootstrap_subtheme_front_office/fonts/source-sans-pro-v11-latin-regular.woff2 https://www.domaine.com/themes/custom/bootstrap_subtheme_front_office/fonts/source-sans-pro-v11-latin-regular.woff2

Specifying the character set used by the page in the HTTP Content-Type header allows the browser to start its analysis right away.

How can I fix that ?


Solution

  • WOFF has its own binary file format, so there is really no need to specify a character set.

    Specifying a character set speeds up the display of pages in the browser.

    Specifying the character set used by the page in the HTTP Content-Type header allows the browser to start its analysis right away.

    This is used for html pages: most pages use something like <meta charset="utf-8"> in the html code. The problem is that the browser doesn't know the character set until it reaches and parses that <meta> tag. If that character set is different from the default setting, the browser has to reparse the page.

    If the character set is specified in the HTTP headers instead:

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

    the browser knows the character set before it starts parsing the page.