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.
Very good note!