开发者

How to use browser caching effectively for images?

Which combination of http headers can achieve the following?

I would like static content like images to be cached for as long as possible, but if those images change on the se开发者_开发技巧rver, I would like the browsers to update them.


A very neat caching approach of static content is to encode version of your static content inside URL. Then "notifiying" browser to download new static content is just a matter of supplying new URLs to the client.


# first version access (1.1/main.css will never expire)
# e.g. by far future Cache-Control + Expires Header
<link ... href="/static/1.1/main.css

# after upgrading/releasing trigger fresh download
<link ... href="/static/1.2/main.css

It involves some effort to your build+deploy process but from caching control it is the very simple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜