David H
David H

Reputation: 1401

How can I set expire headers on my web page?

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

Upvotes: 1

Views: 6592

Answers (3)

alt
alt

Reputation: 13947

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/

Upvotes: 3

gmhk
gmhk

Reputation: 15960

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

Upvotes: -2

Related Questions