Search code examples
wordpressapache.htaccesscachingmod-expires

May mod_expire conflict with Wordpress updates?


I would like to use mod_expire for caching content of my Wordpress blog in the user's browser and increase thereby my ranking at YSlow and Google Pagespeed. So I wanted to use a configuration like the one below.

Header unset ETag
FileETag None

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
<FilesMatch ".(ico|jpg|png|gif|css|js|gz)$">
ExpiresDefault A2592000
Header append Cache-Control "private"
</FilesMatch>
</IfModule>

However, the following question arises for me now. What if a plugins code break and the plugin developer publishs an update? I'll download and install it to my blog, but the broken .js-file from the plugin was cached by the user's browser.
Will the users get a broken view of my page until the cache time expires or will they automatically get served the new one from the plugin's update?


Solution

  • Your concern is founded: browsers will indeed keep using their the cached (possibly outdated) copy until it expires per your config.

    Here is a helpful summary of Expires vs. Last-Modified/ETag, including some suggested best practices.

    Generally speaking, in your case (since you seem concerned about plugin updates) I'd go with ETag/Last-Modified instead of Expires.

    One other idea: you need not bundle js files with all other types. Just a heuristic but it might help:

    # can be safely cached
    <FilesMatch ".(ico|jpg|png|gif|css|gz)$">
        ExpiresDefault now plus 30 days
        FileETag None
        Header unset ETag
    </FilesMatch>
    
    # don't cache or only cache briefly
    <FilesMatch ".js$">
        FileETag MTime Size
        # or: ExpiresDefault now plus 6 hours
    </FilesMatch>