admin管理员组文章数量:1404586
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.
本文标签: phpHow to add farfuture expires headers to minified cssfilesscriptsStack Overflow
版权声明:本文标题:php - How to add far-future expires headers to minified cssfilesscripts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744840214a2627880.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论