开发者

How can I use .htaccess to send distant expiry headers on CSS and JS files?

I want my CSS and JS files to expire in the distant future.

Can I do this with .htaccess alone?

How would I 开发者_Python百科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


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>


<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.


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 :))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜