1

My WordPress site htaccess file currently has these entries to set cache expiry for woff and woff2 font files:

<IfModule mod_expires.c>
  # Content type
    AddType application/font-woff   .woff
    AddType application/font-woff2  .woff2
    ExpiresActive on
  # Web fonts
    ExpiresByType application/font-woff   "access plus 1 year"
    ExpiresByType application/font-woff2  "access plus 1 year"
</IfModule>

But I'm still getting suggestions to set cache TTL for these files in speed testing tools. Here's one example with a cache efficiency problem: https://gtmetrix.com/reports/bydik.com/ad8hZTzh/

enter image description here

Is there anything wrong with my htaccess file? How can I solve this?

4
  • To clarify, you are serving these font files directly from your server?
    – MrWhite
    Commented Dec 11, 2020 at 9:50
  • 1
    Yes. They are served directly from my server.
    – akarim
    Commented Dec 11, 2020 at 9:54
  • Are you using a CDN? "cache TTL" - Does the suggestion really state "TTL" (Time-To-Live)? TTL is a DNS/CDN term.
    – MrWhite
    Commented Dec 11, 2020 at 10:08
  • Here's the result I'm talking about- tools.keycdn.com/speed?h=5fd3449203b8e4746a0abdc2 ... Please see the first two URL of "Efficient cache policy" section.
    – akarim
    Commented Dec 11, 2020 at 10:13

1 Answer 1

1
ExpiresByType font/woff2  "access plus 1 year"
ExpiresByType application/font-woff2  "access plus 1 year"
ExpiresByType application/x-font-woff2  "access plus 1 year"

You need to set ExpiresActive On (at the top) for these directives to have any effect.

You also don't need all 3 of these directives. You should check the Content-Type HTTP response header for the mime-type your server is sending with this resource - it can only be one. The mime-type needs to match the response from your server.

To determine whether these directives are working or not, you should check for the Expires and Cache-Control: max-age headers in the HTTP response.

UPDATE: You are using a CDN (Cloudflare), so ultimately the cache response headers are going to be determined by the CDN.

You are serving two font files:

  1. https://example.com/libs/fonts/fontsolaimanlipi.woff
  2. https://example.com/fonts/fontawesome.woff2

The first is a woff font file (not woff2) and is sent with a application/x-font-woff mime-type (so the above directives would need to be modified for this).

The second is not sending a Content-Type header at all (so the above directives will not apply, unless you have an ExpiresDefault directive?), so maybe your server is not enabled for this mime type. For example:

AddType font/woff2 .woff2

Or maybe this can be configured in the CDN.

5
  • "ExpiresActive On" is on my htaccess and there was just one line (application/font-woff2) previously. I've added the other two later to solve the issue.
    – akarim
    Commented Dec 11, 2020 at 10:01
  • What are the actual headers in the HTTP response?
    – MrWhite
    Commented Dec 11, 2020 at 10:08
  • I've updated my answer
    – MrWhite
    Commented Dec 11, 2020 at 10:30
  • I've updated my question with new details.
    – akarim
    Commented Dec 11, 2020 at 12:52
  • The HTTP response doesn't appear to have changed and it's coming from Server: cloudflare - so it's possible we are just seeing a cached response from Cloudflare? This maybe something that needs "fixing" at Cloudflare.
    – MrWhite
    Commented Dec 11, 2020 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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