Setting obsolete headers and gzipping data via .htaccess

I am trying to configure it so that the browser caches webfonts for a long period of time, and also tries to gzip them for faster loading.

From what I can understand, you can do this through your httpd.conf file in Apache or through .htaccess .

I'm not sure how to tell if gzip is enabled, I read something about finding your httpd.conf file for DEFLATE ; I did this, but did not find anything - so I'm not sure if it is turned on or not !?

In any case, I put this code below in the .htaccess file, partly because I did not know where to put it in the httpd.conf file, and partly because it was easier to make changes to the .htaccess file, without disturbing my host constantly.

Here is the code.

 # Add correct content-type for fonts AddType application/vnd.ms-fontobject .eot AddType font/ttf .ttf AddType font/otf .otf AddType font/x-woff .woff AddType image/svg+xml .svg # Compress compressible fonts AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml # Add a far future Expires header for fonts ExpiresByType application/vnd.ms-fontobject "access plus 1 year" ExpiresByType font/ttf "access plus 1 year" ExpiresByType font/otf "access plus 1 year" ExpiresByType font/x-woff "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" 

Now I'm wondering if this is correct or not, since I also saw this similar but different code for the expiration.

 ExpiresByType application/x-font-ttf "access plus 1 month" ExpiresByType font/opentype "access plus 1 month" ExpiresByType application/x-font-woff "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" ExpiresByType application/vnd.ms-fontobject "access plus 1 month" 

It doesn't matter where you put it in the .htaccess file, or can it go anywhere?

+4
source share
1 answer

ExpiresByType can go to your httpd.conf, virtualhost config or htaccess, as shown in the apache documentation overview window at the top of each directive entry:

Apache Documentation screenshot

http://httpd.apache.org/docs/2.2/mod/mod_expires.html#expiresbytype

A list of contexts is how you can specify which configuration files you can put in your various types of Apache directives.

Assuming you are using PHP, your phpinfo data should tell you whether gzip is enabled.

PHPInfo Screenshot

Edit

In response to your question regarding the correct MIME type for your fonts, in terms of their association of files with Apache Server, my mime.types file (located in the apache conf folder where your httpd.conf lives) tells me that

 application/x-font-(extension) 

is an association for use with ExpiresByType. I would suggest that you start the fonts first, and then check the headers for the font URL to see if it gives the correct expiration date.

enter image description here

As for browsers receiving web fonts, this article seems to indicate that MIME types are not considered and therefore are not relevant, But still this one seems to contradict this. As far as I understand, there is no official font / MIME type, so any browser implementation goes beyond the MIME specifications.

Related questions:

The correct MIME type for fonts

Valid Apache AddType directives for MIME type fonts

I havenโ€™t seen anything that indicates placement requirements in .htaccess, so you have to be safe by setting these rules wherever you are, although if you use AddTypes you need to do this above any other directives that reference the declared a type. It is probably best to put them on top of rewriting rules.

+3
source

Source: https://habr.com/ru/post/1445342/


All Articles