RSS

Adding Expire Headers to Htaccess File

Wed, Jun 10, 2009

Code, PHP

Adding expire headers is a good way to keep client requests to a minimum. Without them every time the client’s browser requests a file the server has to serve it. Adding expire headers, in this case to the .htaccess file, keeps a cached version of the requested file on the client’s computer in case it is requested again. For example, you have an image gallery. The client clicks on a picture, the picture is served to them, fine. Now when the client clicks the link at the top of your page to return to the main gallery page, ALL those thumbnails of the large images are requested from the server. With this code the client merely retrieves the same images he originally saw again, without the extra server requests. Nice isn’t it?

<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
Header set Expires "Fri, 10 Jun 2050 00:00:00 GMT"
Header set Cache-Control "public, no-transform"
</FilesMatch>

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • MySpace
  • Twitter
  • Yahoo! Buzz
  • PDF
  • Reddit
  • Slashdot
  • Technorati
,

1 Comments For This Post

  1. KonstantinMiller Says:

    You know so many interesting infomation. You might be very wise. I like such people. Don’t top writing.

Leave a Reply