简体   繁体   中英

How can you prevent Internet Explorer from caching HTML without using random query-strings

We are currently using random query-strings to prevent Internet Explorer from caching HTML on postbacks, but we are in the process of implementing URL re-writing and it would be nice if we could remove these random parameters.

What's the best pratice in this situation?

Have you tried the no-cache and expires meta-tags ?

Other than that, random generated query-strings are the way to go. In my opinion, its not not that big of a deal. domain.com/stories/man-walks-on-moon/s34b is not exactly making my eyes bleed. And you will still achieve great indexing as far as search engines go.

The proper way to control caching is to use proper caching headers. http://www.fiddler2.com/redir/?id=httpperf describes this at length.

Using random query-strings is a simple hack to deal with cases where you don't control the server's headers.

Speaking of HTTP headers, the following combination makes typical browser to reload a page:

Cache-Control: no-cache, no-store, max-age=0
Pragma: no-cache
Expires: -1

If HTTP headers aren't controllable, META tags in HTML head will do. However IE isn't your typical browser especially when the back button is hit. On my experience even with headers above set, the back button will not bother to ask server but will restore the page from cache. But there is a way to fight this: add another header:

Vary: *

This one will cause IE 7-8 to reload page on back button hit as well.

如果安装了Internet Explorer 8或Developer Tools插件,则可以从插件窗口的“缓存”菜单中选择“始终从服务器刷新”(按“F12”显示)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM