Using browser cache image expiry for performance

Browser cache for images is a great feature and potential area of improvement to enhance web page performance. We can tell browser to use images from cache and should not request these from server until they expire.

Apache server makes it really easy to add expiry time for images through .htaccess file.
As images used in design of website are not changed often so it is good idea to set expiry in 30 days or more. The product images used in listing can be set to expire after 7 days.

To set expiry you will need to edit your .htaccess file in images directory. Use following code to set expiry time for images

<ifmodule mod_expires.c>
    <filesmatch "\.(jpg|JPG|gif|GIF|png|css|ico)$">
        ExpiresActive on
        ExpiresDefault "access plus 7 day"
    </filesmatch>
</ifmodule>

The code above tells browser that the images and css files have expiry of 7 days.

5 Responses to “Using browser cache image expiry for performance”

  1. Very good note!

  2. Hi. Is this specific to wordpress, or CRE? Since you are using the module mod_expires i suspect the htaccess wording would have to be different for someone using another CMS.

    Thanks

  3. Oups ok i saw this is an apache module :) Thanks a lot i’m improving my cache right now!

  4. Hello,

    some of my clients are using a windows server for there web sites. How i enable browser caching there, or any alternative?

  5. On Windows IIS server there is an option to add custom header. This setting is done of each virtual directory. I am not sure if hosting companies allow such settings. There must be some way to do it for share hosting but I don’t know how to do it. If you find a solution plz post it here as well.

Leave a Reply