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 ar开发者_StackOverflow社区e 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.
If you have Internet Explorer 8 or the Developer Tools plugin installed, you can select "Always Refresh from Server" from the "Cache" menu on the plugin window (press 'F12' to show it).
精彩评论