how to i add add far-future expires headers to minified cssfiles/scripts? I am using minify to bine css files and javascripts files, but the minified versions don't have a far-future expiration date.
how to i add add far-future expires headers to minified cssfiles/scripts? I am using minify to bine css files and javascripts files, but the minified versions don't have a far-future expiration date.
Share Improve this question asked Dec 15, 2010 at 22:34 ZhiancZhianc 1,4515 gold badges20 silver badges37 bronze badges3 Answers
Reset to default 3If you're using Apache, then this sort of thing is the way to go. There are several different ways to do it depending on the modules installed; some make it easier than others. I remend the expires
(docs) and headers
(docs) modules (they're both required for the example below, but you can pull it off with only headers
if you really want).
<LocationMatch "/js/(.*)\.js">
ExpiresDefault "access plus 10 years"
Header set Cache-Control "public"
</LocationMatch>
This example matches all files in /js/ that end with a .js extension and set an expiry time of 10 years into the future relative to the time the file is accessed. It also explicitly sets Cache-Control to be public; we run everything over SSL, so it might not be necessary otherwise, but it won't hurt you either way.
This example can easily be extended to match your CSS locations and files as well; just copy, paste and change the LocationMatch.
There are plenty of sites that will give you a full rundown on this; check out this one, "Caching Tutorial", which seems to cover it all.
/min/README.txt has documentation for sending far-future expires headers.
Minify can send far-future (one year) Expires headers. To enable this you must add a number to the querystring (e.g.
/min/?g=js&1234
or/min/f=file.js&1234
) and alter it whenever a source file is changed. If you have a build process you can use a build/source control revision number.You can alternately use the utility function Minify_getUri() to get a "versioned" Minify URI for use in your HTML.
That depends on what web server you are using. It can't be done by modifying the CSS or script files themselves, though.