Gzip compression of EOT, TTF, WOFF and WOFF2 fonts and others
A computer font is a file containing 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 download speed of one of the sites, PageSpeed Insights reported that Gzip compression was not applied to the file with * .WOFF2 fonts, although it was turned on and configured for a long time.
How to compress plug-in fonts using Gzip, we will describe later in our article.
To date, four font container formats are used on the Internet: EOT, TTF, WOFF and WOFF2 . But unfortunately, as is usually the case, despite the possibility of 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 widely distributed, but it cannot be used in some older browsers.
- Over support WOFF 2.0 are currently working.
There is another font container format - SVG . But it was never supported in Internet Explorer and Firefox. And now it is no longer used in the Chrome browser.
In this regard, we need to use all these formats so that the page looks the same among users of different browsers.
Continue on compression. Since I have Nginx running as a front-end on the server and Apache backend, it was enough for me to turn on Gzip only in Nginx. It is included very simply. It is necessary to add a line in the configuration file:
Now we will list the pharmacy files we need to compress through Gzip:
In Ubuntu Server, this file is here: /etc/nginx/nginx.conf
Restart Nginx for the changes to take effect: nginx -s reload
For more detailed settings of Gzip-compression in Nginx can be found on the official website of Nginx.
In the same file, be sure to check the values of the gzip_types parameter. First of all, it is there that application / font-woff2 is most often not specified, and therefore this font file was not processed by Gzip compression. At the same time, check for the presence 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 if these types are listed in this file. Below I just give the contents of this entire file:
After that, restart Nginx: nginx -s reload .
Via matovsky.com & wiki