javascript - Hard refresh and XMLHttpRequest caching in Internet Explorer/Firefox -


i make ajax request in set response cacheability , last modified headers:

if (!string.isnullorempty(httpcontext.current.request.headers["if-modified-since"])) {     httpcontext.current.response.statuscode = 304;     httpcontext.current.response.statusdescription = "not modified";     return null; } httpcontext.current.response.cache.setcacheability(httpcacheability.public); httpcontext.current.response.cache.setlastmodified(datetime.utcnow); 

this works expected. first time make ajax request, 200 ok. second time 304 not modified.

when hard refresh in chrome (ctrl+f5), 200 ok - fantastic!

when hard refresh in internet explorer/firefox, 304 not modified. however, every other resource (js/css/html/png) returns 200 ok.

the reason because "if-not-modified" header sent xmlhttprequest's regardless of hard refresh in browsers. believe steve souders documents here.

i have tried setting etag , conditioning on "if-none-match" no avail (it mentioned in comments on steve souders page).

has got gems of wisdom here?

thanks, ben

update

i check "if-modified-since" against stored last modified date. however, question other users find header set incorrectly.

update 2

whilst request sent "if-modified-since" header each time. internet explorer won't make request if expiry isn't set or set future date. useless!

update 3

this might live blog now. internet explorer doesn't bother making second request when localhost. using real ip or loopback work.

prior ie10, ie not apply refresh flags (see http://blogs.msdn.com/b/ieinternals/archive/2010/07/08/technical-information-about-conditional-http-requests-and-the-refresh-button.aspx) requests not made part of loading of document.

if want, can adjust target url contain nonce prevent cached copy satisfying future request. alternatively, can send max-age=0 force ie conditionally revalidate resource before each reuse.

as why browser reuses cached resource didn't specify lifetime, please see http://blogs.msdn.com/b/ie/archive/2010/07/14/caching-improvements-in-internet-explorer-9.aspx


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -