开发者

Force Browser Caching Across Browser Sessions

I help maintain several Wordpress-based websites that publish news and reference information.

We have been working hard to make pages at the websites load as fast as possible.

One of the things we've done is implement very long "max-age" times in the "cache-control" http headers for most of our static files, such as images and css files.

The particular cache-control setting we're using is "public, max-age=31536000". 31,536,000 seconds is 365 days.

The upside is that this setting does, in fact, cause the static files to be cached as visitors browse through different pages of our sites.

But here's the rub. This cache-control setting doesn't do much for us across browser sessions. Even though the setting is supposed to tell the browser "cache this file for an entire year", if a visitor to our site sh开发者_如何学JAVAuts down their browser, then starts it up just five minutes later and comes back to our site, the browser insists on re-loading all the static files, even though it still has them in its cache.

I've checked this carefully in Firefox, viewing the headers with Live HTTP Headers. But I can also qualitatively see the same thing happening in other browsers.

Apparently, browsers insist on re-loading all content for a website if the content hasn't been loaded once during the current browser session.

So ... Is there any way we can "politely suggest" to browsers that they always load cached content from the cache, even if the browser hasn't been to our site during the current browser session?


Check the ETag, Expires, and Last-Modified headers as well.

You need an Expires header, and sometimes ETag and Last-Modified can defeat caching.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜