开发者

How can I set expire headers on my web page?

I aske开发者_如何学God a question about improving CSS load times and one answer suggested setting expire headers on my web page. Can someone explain how I can do this. I've never heard about it before.


This is an apache trick you can do by creating a file called '.htaccess' and placing it in the root of your domain via FTP.

<FilesMatch "\.(css)$">
ExpiresDefault "access plus 2 hours"
</FilesMatch>

Paste that in your .htaccess file and it will set the header f r css files. Add more filetypes, (css|js)

or cache-control for non-apache users:

<ifModule mod_headers.c>
  <filesMatch "\\.(css)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
</ifModule>

In fact, use all of the tricks your server supports in this article, your site will be noticeably faster:

http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/


http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching


This goes in your root .htaccess file but if you have access to httpd.conf that is better

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

For the specified file format will be cached and will prevent users to make extra HTTP requests

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜