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

柔情痞子 提交于 2019-12-07 02:05:52

问题


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:

  • http://www.mysite.com/components/com_arrcard/assets/merchant-logos/aap25.jpg (expiration not specified)

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?


回答1:


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.




回答2:


If you're using IIS you can put the images into a separate folder and then set the cache header. If you update an image, change the file name so that it will be refreshed in the browser the next time the user loads the page

Using Content Expiration



来源:https://stackoverflow.com/questions/4098185/how-do-i-add-an-expiration-date-to-an-img-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!