h5bp/server-configs-apache

Add `ExpiresByType` for `audio/mp4` with `"access plus 1 year"`

creopard opened this issue · 3 comments

If you are serving m4a files on a website, it can be helpful to stretch the cache expiration for this type.

The current .htaccess file only includes:
ExpiresByType video/mp4 "access plus 1 year"

However, Google's Lighthouse will complain about m4a files with "Serve static assets with an efficient cache policy", since the default ExpiresDefault of 1 month is too short for this type.

Adding cache expiration for "audio/mp4" like:
ExpiresByType audio/mp4 "access plus 1 year"

will fix that, since the mime type of "audio/mp4" is already included in the "Media types" section:

# Media files
AddType audio/mp4                                   f4a f4b m4a

Thanks for opening this issue, @creopard.
Sounds good. Would you like to open a pull request?

For reference: https://www.iana.org/assignments/media-types/audio/mp4

@LeoColomb it seems this setting has been replaced in the current repo (h5bp/web_performance/cache_expiration.conf) by:

# Generic: Medias
# ExpiresByType audio/* "access plus 1 year" # default

So I guess that's optional now?
Will the build script replace the asterisk (*) in these lines with the specific file extensions like "mp4"?

Oh yes, indeed, it is already covered.
There is no build script for this part, the * can be used to "glob" all audio/video prefixed MIME-types. This is interpreted directly by httpd server.
And that part is commented out as it is falling back in the default case perfectly.

# Default: Fallback
ExpiresDefault "access plus 1 year"

In short, yes, audio/mp4 is already been handled correctly.
For this reason, I'm closing the issue, but continue the discussion below if any question.