Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting expire headers for fonts not working

I am using the below code in my .htaccess file to try and set the expire headers for some fonts, but upon checking my firefox cache and the expire header, the font is set to expire in about 12 hours from now; not the 1 year I am trying to set it to.

Here is my code:

# Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg

# Compress compressible fonts
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-opentype image/svg+xml

# Add a far future Expires header for fonts
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"

What am I doing wrong?

like image 245
Brett Avatar asked Nov 17 '12 10:11

Brett


People also ask

Should I add expired headers?

Adding Expires Headers is important to reduce HTTP requests which reduces the time it take for the server to communicate with the browser. It also allows your users to reuse the cache files that have been stored in the browser to reduce the amount of files they need to download.

What is an expire header?

The expires header is an HTTP header that indicates whether it is possible to obtain information on request from the browser cache or if you need to access the server since the page option in the cache is already outdated. This header contains the date and time until the page is available in the browser cache.


1 Answers

Seems I had to include this bit as well:

ExpiresActive on 

With the full code being:

# Add correct content-type for fonts AddType application/vnd.ms-fontobject .eot AddType font/ttf .ttf AddType font/otf .otf AddType font/woff .woff AddType font/woff2 .woff2 AddType image/svg+xml .svg  # Compress compressible fonts AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml  ExpiresActive on  # 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/woff "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" 
like image 189
Brett Avatar answered Sep 19 '22 13:09

Brett