Mod_expires ExpiresByType file types

I am puzzled by the number of directives used for each type of file when using mod_expires. For example, for icon files there appear to be 6 directives:

ExpiresByType image/ico                           "access plus 1 month"
ExpiresByType image/icon                          "access plus 1 month"
ExpiresByType text/ico                            "access plus 1 month"
ExpiresByType image/x-ico                         "access plus 1 month"
ExpiresByType image/x-icon                        "access plus 1 month"
ExpiresByType application/ico                     "access plus 1 month"

Are all these directives needed? If not, how do I know which one(s) to use?

Have you considered converting all the file types to WebP format? I recently converted all image files on a site and the savings were appreciable. The following single declaration could then be used:

AddType image/webp .webp

I used ImageMagick to convert all the images into a new folder and it only took seconds.

That doesn’t really answer the question, John. I gave icons as an example. There are other file types (eg fonts) that seem to require multiple directives, too.

But to answer your question, yes I have thought of using webp images but they only have partial support in Safari, so it’s not worth it for me for now.

And I’m not sure favicons can be webp files can they?

1 Like

I’m using a tablet at the moment and cannot check if ImageMagick converts favicon.ico files but the following site is worth checking:

https://www.freeconvert.com/ico-to-webp

Support

https://www.keycdn.com/support/webp-browser-support

I’m not sure about fonts.

Using Gtmetrix.com is quite good for highlighting files which do not have their ExpiresByType set.

One thing I have noticed is that WebP image-background URLs were not cached unlike the other WebP images?

Edit:

I get the general impression that using a CDN is more beneficial than setting ExpiresByType

Presumably you only need them for file types that actually exist on the site. Do you use all those types of icon?

I’ve not tried with WebP, but I would think it possible. I can use PNG and SVG for favicons, they don’t have it be ICO files.
In the context of icons, being so small I’m not sure how significant saving you would get with WebP. In the past I always favoured PNG for graphical style images like icons, as their compression lends itself well to that type of image. But now I use SVG for that kind of thing and the files are tiny.
WebP is worth looking at for more photo type images, particularly any with alpha, as PNG are usually quite inefficient with photo images and Jpegs don’t support alpha.

I’ve just got a favicon.ico file which contains 3 sizes of file, but which type it is I don’t know.

I also have woff font files but I have no idea whether they are application/x-font-woff or application/font-woff. Hence the confusion.

Hah, I’ve discovered my host has published a list of recognised MIME types, so now I know which ones to use!

Edit: and when I need to use AddType.

1 Like

Stuff like that is easy to find out.

  1. Use this
ExpiresByType image/ico                           "access plus 1 hour"
ExpiresByType image/icon                          "access plus 2 hour"
ExpiresByType text/ico                            "access plus 3 hour"
ExpiresByType image/x-ico                         "access plus 4 hour"
ExpiresByType image/x-icon                        "access plus 5 hour"
ExpiresByType application/ico                     "access plus 6 hour"
  1. Do a curl -I <url> request to do an HTTP HEAD request and see how far out it is caching
  2. Calculate back from that to which mime type was detected by Apache.
2 Likes

^ cunning, squire. Cunning!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.