Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up mod expires for fonts

I'd like to set expiry date for fonts. Following definition isn't working on apache 2.2.15.

ExpiresByType application/x-font-woff       "access plus 1 month"
ExpiresByType application/font-woff2         "access plus 1 month"
like image 276
user3796291 Avatar asked Jul 03 '16 01:07

user3796291


People also ask

How to use mod_expires in htaccess?

Using mod_expires in .htaccess allows image types and other file types to be set in an array. This matches the file types to the specific expire time. This streamlines the htaccess code. In the code below, the file types are listed in a row like jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3. Below is an example of the code to use.

Should I put an expiration date on my static components?

If those static components are NOT going to change because they’re graphics (generally tiny graphics, too) or consistent files, then you should not have to worry about putting an expiration date on them. The Gtmetrix page is for determining how best to optimize your site for speed purposes.

What happens if the expire module is not enabled?

Enabling the expire module also wont work till the expire time set by the Heuristic expiration policies expires. After it expired, a new exipre time wont be set by Heuristic expiration policies as we enabled the expire module. If no expire module enabled then again a new expire date is set by the Heuristic expiration policies.

How do I make my website's CSS and HTML expire?

Make your CSS, HTML, and Javascript expire at a minimum of a month like “access plus 1 month”. CSS, HTML and JavaScript’s typically are updated more when developing a site than the sites images. Keep your cache expire date at most a year. mod_gzip_item_include mime ^text/.*


2 Answers

First, add proper MIME types definitions:

AddType application/font-sfnt            otf ttf
AddType application/font-woff            woff
AddType application/font-woff2           woff2
AddType application/vnd.ms-fontobject    eot

Next, change your configuration lines to:

ExpiresByType application/font-woff "access plus 1 month" 
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/font-sfnt "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
like image 96
Danila Vershinin Avatar answered Oct 25 '22 09:10

Danila Vershinin


I find it easier to use file extensions rather than mine types, especially as the Woff mime type changed a few times.

# Set up caching on font files for 6 months (60 * 60 * 24 * 180 = 15724800)
<filesMatch ".([eE][oO][tT]|[tT][tT][fF]|[sS][vV][gG]|[Ww][Oo][Ff][Ff]|[Ww][Oo][Ff][Ff]2)$">
   ExpiresDefault A15724800
   Header append Cache-Control "public"
</filesMatch>
like image 31
Barry Pollard Avatar answered Oct 25 '22 09:10

Barry Pollard