With eZ Publish (legacy), the ezjscore extension is critical for loading, concatenating, and minifying JS and CSS files. It places the generated JS and CSS files in the /var/[site_name]/cache/public/ folder.
You can instruct browsers to cache these files for a long time with an Apache configuration such as this:
<LocationMatch "^/var/[^/]+/cache/public/.*"> # Force ezjscore packer js/css files to be cached 90 days at the client side ExpiresActive on ExpiresDefault "now plus 90 days" SetOutputFilter DEFLATE Header merge "Cache-Control" public </LocationMatch>
When you modify a JS or CSS file, you want users to get the changes immediately. If the same JS and CSS file names are referenced by your website pages, then you have to worry about clearing the cache at the CDN or reverse proxy level and also at the browser level. It is also not possible to force all users to clear their browser cache. Therefore, you can instruct ezjscore to generate new file names whenever the eZ Publish cache is cleared with this setting in an override of ezjscore.ini.append.php:
This will make the JS and CSS file names something like this, with a timestamp appended:
The additional complication is with cached pages that still reference the old JS and CSS file names. You don't want to have to clear your entire site's page caches (especially at the CDN or reverse proxy level) whenever a JS or CSS change is released, so you have to consider that a stale cached page is still relevant -- not a desirable situation, but sometimes necessary. Unfortunately, when you clear ezjscore's cache, this removes all old generated JS and CSS files and can break those old links. With some additional configuration, you can keep these old generated files (who have file names that don't clash with your new generated files) on your server a bit longer. To do so, you'll need a new PHP class that will only delete generated files that are older than a certain amount of days. This example works for eZ DFS cluster configurations.
(Note: an alternative is to have an even longer caching time for JS and CSS files at your CDN or reverse proxy, but it is riskier as you could have cache expire earlier than expected if, for example, you have to restart your reverse proxy.)
First, add the following configuration to an override of site.ini.append.php:
[Cache_ezjscore] class=MugoJSCCacheManager # maxage is the maximum age a packed ezjscore .css or .js is allowed to be # This is used to preserve the packed files for the timespan indicated # Use any time that will work well with strtotime, for example "90 days" # Do not use a minus sign - one will be added by the code maxage=90 days
Then, your new PHP class should have a function called clearCache() that does the following:
Commentsblog comments powered by Disqus
Hi, we're Mugo Web - Nice to meet you!
We're a group of web experts who solve complex web problems.Learn more about us »
- Business solutions (79)
- Case study (28)
- eZ Publish add-ons (22)
- eZ Publish community (11)
- eZ Publish development tips (67)
- Front-end development (4)
- Productivity tools (18)
- Site performance (13)
- User experience (34)
- Web accessibility (14)
- Web solutions (76)
- Work at Mugo (12)
Yes - we can do that.
Many years of experience with complex websites allows us to offer total solutions.Learn more about what we can do »
We love our clients (and they love us too)
We've solved problems across North America and around the world.Learn more about what we've done »
We tweet too
Follow us on Twitter for the latest Mugo happenings