I want my CSS and JS files to expire in the distant future.
Can I do this with .htaccess alone?
How would I do it?
I know in the future if I change one I will need to force a redownload, something like this should work
script.js?v=12
I want my CSS and JS files to expire in the distant future.
Can I do this with .htaccess alone?
How would I do it?
I know in the future if I change one I will need to force a redownload, something like this should work
script.js?v=12
<FilesMatch "\.(js|css|)$">
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>
That should do it for you. You can obviously adjust the date and time for whenever. Just remember, you need to change the name of the file if you update it.
This uses mod_expires
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "now plus 1 year"
ExpiresByType text/javascript "now plus 1 year"
</IfModule>
I use something like this:
<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=4838400, public"
</FilesMatch>
<FilesMatch "\.(css|js)$">
Header set Cache-Control "max-age=4838400, private"
</FilesMatch>
</IfModule>
age in seconds of course :))