26

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?

5
  • 1
    @jww Was this really a necessary comment after 5+ years? If you're so concerned about "on-topic" questions perhaps you should go and troll newer questions instead!? :)
    – Brett
    Commented Feb 17, 2018 at 11:10
  • The problem is, people see this question and then ask similar questions. The only way I know to signal off-topic-ness that persists over time is the custom close message.
    – jww
    Commented Feb 17, 2018 at 11:18
  • 3
    @jww .htaccess IS on topic. See this FAQ article.
    – Papershine
    Commented Feb 17, 2018 at 11:19
  • 1
    @paper1111 - For a question to be on-topic here, it must satisfy both "software tools commonly used by programmers" AND "practical, answerable problem that is unique to software development". Apache config files certainly don't satisfy the later. Anything else is just wishful thinking.
    – jww
    Commented Feb 17, 2018 at 11:24
  • 3
    @jww I'm with paper1111 on this one. According to that meta question it is fine. Additionally, this is why a lot of people get ticked off with some of the people @ SO - because there are so many anal people that get overzealous in screaming something is off-topic or a duplicate.
    – Brett
    Commented Feb 17, 2018 at 16:48

2 Answers 2

78

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"
6
  • That worked for me as well. What's weird, though, is that I simply had an ExpiresDefault "access plus 1 month" that was handling all file types (html, jpg, css, js, etc) correctly except svg. Once I added ExpiresActive on, the ExpiresDefault also worked for svg. Any ideas why that would be? Commented Oct 16, 2015 at 18:55
  • Hard to say why it worked for you without ExpiresActive on, but just be sure to always use it in the future to be certain. :)
    – Brett
    Commented Oct 17, 2015 at 5:41
  • 1
    AddType application/font-woff2 .woff2 and ExpiresByType application/font-woff2 "access plus 6 month" for the recommended woff2
    – user9112752
    Commented Jun 2, 2018 at 16:16
  • @BO41 Thanks for that, but any idea why this is font-woff2 and not x-font-woff2 like the others?
    – Brett
    Commented Jun 3, 2018 at 18:09
  • @Brett no sorry. I don't know. maybe the others work without the "x-" as well or it is something browser specific. Didn't find much online. I just know that it works like this in up-to-date chromium and firefox. maybe you find something online (stackoverflow.com/questions/3594823/mime-type-for-woff-fonts)
    – user9112752
    Commented Jun 4, 2018 at 13:43
2

I believe your issue is how you define the fonts, and there is no need to add their content-type

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.