Gzip-compression of EOT, TTF, WOFF and WOFF2 fonts and other
A computer font is a file that contains a description of a set of alphabetic, numeric, service and pseudographic characters used to display these characters (in particular text) by the program or the operating system.
When developing Internet projects, plug-in fonts are used. However, after testing the speed of loading one of the sites with the PageSpeed Insights tool, a message was issued saying that the file with * .WOFF2 fonts does not use Gzip compression , although it has long been enabled and configured.
How to compress the connectable fonts using Gzip, we will discuss later in this article.
To date, the Internet uses four formats of font containers: EOT, TTF, WOFF and WOFF2 . But, unfortunately, as usual, despite the choice, there is no single format that would work in all browsers:
- EOT is available only in Internet Explorer.
- TTF is only partially supported in this browser.
- WOFF is more common than others, but it can not be used in some older browsers.
- Over the support of WOFF 2.0 are working now.
There is another format for the font container - SVG . But it was never supported in Internet Explorer and Firefox. And now it ceases to be used in the Chrome browser.
In this regard, we need to use all these formats to make the page look the same for users of different browsers.
Let's continue with compression. Since I have Nginx as the frontend on the server and the Apache backend, it was enough to enable Gzip only in Nginx. It turns on very simply. You need to add a line in the configuration file:
Now, we list the file pharmas that we need to compress through Gzip:
In Ubuntu Server, this file is located here: /etc/nginx/nginx.conf
For the changes to take effect, restart Nginx: nginx -s reload
More detailed settings of Gzip-compression in Nginx can be found on the official site of Nginx.
In the same file, be sure to check the values of the gzip_types parameter. First of all, it usually does not specify application / font-woff2 , and therefore this font file was not processed by Gzip-compression. At the same time, check the availability of other font formats:
application / x-font-ttf application / vnd.ms-fontobject application / font-woff application / font-woff2
That's not all. Now open /etc/nginx/mime.types and check whether these types are listed in this file. Below, I will simply list the contents of this entire file:
After that, restart Nginx: nginx -s reload .
Via matovsky.com & wiki