1

Following old advices here and here I'm curious what is the proper syntax for APACHE server:

AddType font/woff2 .woff2 
ExpiresByType font/woff2 "access plus 1 year"

or

AddType application/woff2 .woff2 
ExpiresByType application/woff2 "access plus 1 year"
Plamen
  • 320
  • 4
  • 19

2 Answers2

1

what is the proper syntax for APACHE server

It's not really a question of "syntax". Both your examples use the same "syntax". But rather, what is the correct/official mime-type (that user-agents understand).

The official mime-type according to the WOFF2 spec (W3C Recommendation / 1-March-2022) is:

font/woff2

This was initially discussed in the WOFF File Format 2.0 - W3C Working Draft 14 April 2015 - Appendix A: Internet Media Type Registration

AddType application/woff2 .woff2 

I don't think application/woff2 has ever been a (proposed) mime-type? The IANA Media Types initially defined application/font-woff for woff font files, so by extension you could assume that application/font-woff2 would be used for woff2, but I don't see this documented anywhere? And IANA have since "deprecated" application/font-woff in favour of font/woff and list only font/woff2 for woff2 font files.

AddType font/woff2 .woff2 

You shouldn't need to manually add the AddType directive here. Providing you are using a relatively recent distro of Apache then the mime.types file that is imported (using the TypesConfig directive) during startup already includes the necessary (and correct) mime-type for .woff2 files:

font/woff2                  woff2

See also:

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Nice explanation MrWhite! – Valeriu Ciuca Oct 21 '22 at 07:48
  • "You shouldn't need to manually add the AddType directive here" - I also was curious do I need AddType at all. Apache version is 2.4.54 – Plamen Oct 21 '22 at 08:32
  • In this server I have mime type of fonts by default: font/collection ttc; font/otf otf; font/ttf ttf; font/woff woff; font/woff2 woff2; – Plamen Oct 21 '22 at 08:37
  • "do I need AddType at all" - you might if you were distributing your application/config across many servers where this mime-type might not be defined. But if that was the case then you would need to write your code very defensively (unless you consider these rules mandatory) as the modules themselves might not be enabled. However, that's not how you would write the code if this is your own server. @pl71 – MrWhite Oct 21 '22 at 17:08
0

Did you include the ExpiresActive on?

<IfModule mod_expires.c>
  ExpiresActive On
  AddType font/woff2 .woff2 
  ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
Valeriu Ciuca
  • 2,084
  • 11
  • 14
  • Yes, ExpiresActive is on. The question is mainly regarding the syntax, it looks like both are valid - with `application` and with `font`. I'm checking also https://stackoverflow.com/questions/28235550/proper-mime-type-for-woff2-fonts. – Plamen Oct 20 '22 at 20:59
  • Yes, I think they are both valid, because you declare their type first, and that defined type is the key used by ExpiresByType to the expiring date. – Valeriu Ciuca Oct 20 '22 at 21:01
  • But it depends what the user-agent/browser will accept (not just what happens with mod_expires). Unless the UA is performing additional type-sniffing, it may not accept `application/woff2` (note this is arguably missing the `font-` prefix on the subtype). @ValeriuCiuca – MrWhite Oct 21 '22 at 00:05
  • @ValeriuCiuca "I am using something like these" - although this would seem to be a bit dated. `text/javascript` / `application/x-javascript` - Note that the official mime-type for JS files is `application/javascript`, which is more likely to be what your server is sending these days. And `image/svg+xml` as opposed to `image/svg`. `application/x-shockwave-flash` - hhmmm, probably not much use anymore? – MrWhite Oct 21 '22 at 00:24
  • 1
    I removed that code. It was from an old project that still used Apache + .htaccess. Thx. – Valeriu Ciuca Oct 21 '22 at 07:45