Search code examples
htmlcache-control

how do I add an expiration date to an img tag?


I'm using the Page Speed Firebug extension to help improve page performance. I have an image-heavy page, and one of the suggestions it made is this:

Leverage browser caching The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

I know you can set Expires or Cache-Control headers on an entire page, but how do I add an expiration to a specific element? Is it even possible, or am I misinterpreting what Page Speed is suggesting?


Solution

  • Presumably you'd set the expires or cache-headers on an image by using some sort of setup in your webserver (either configure a specific directory or use a script) so that the http request sent for each image also contains these attributes.

    If you're using apache, one option to do this for you is mod_expires.