Setting expiry times for images to speed up site

Hi,

I recently went into Google speedinsights to get further information re whether my site is responding at optimum speed. I was told that i need to set expiry times on the images on my pages.

How can I do this and what kind of expiry time should I set?

thanks,

[FONT=Verdana]If you’re using Apache, you can add expiry information in your .htaccess file. For example:

# Enable the mod_expires module
ExpiresActive On
# Set expiration date to 1 month for all style sheets and images
ExpiresByType text/css "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
# Set expiration date to 1 week for all HTML pages
ExpiresByType text/html "access plus 1 week"
ExpiresByType application/xhtml+xml "access plus 1 week"

What time-scale you choose depends on how likely you are to amend the image. The expiry is basically saying it’s OK to serve a cached copy of this resource for another day/week/month or whatever after it’s been accessed. For images, it’s probably safe to set a lengthy expiry, because if you change the image, you’re likely to replace it with one with a different file name i.e. a completely different resource.

There’s a good tutorial here that you might find useful.[/FONT]

Thanks for this - but being a very green php person - would I put this into .htaccess exactly as it is above or would I need to add the names of the images?

You don’t need to specify images, just image type. So if, for example, you don’t have any gifs, you can omit that line. Just include the lines that apply to your site. (Or use them all, if you think you might add other content-type in future and forget to update the .htaccess file. ;))