Question

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?

Was it helpful?

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>

OTHER TIPS

this script just caches, ico, jpg, png, gif, css, js, gz files not html. Wordpress will be fine.

if you are having a client side js crash, simply don't cache the js. Or re run this same again and set js to cache for a short time, like 14400 s.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top