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 shuts 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.

链接地址: http://www.djcxy.com/p/55740.html

上一篇: WCF Web API中的HTTP缓存在浏览器中似乎不一致

下一篇: 在浏览器会话中强制浏览器缓存