开发者

Does IE completely ignore cache control headers for AJAX requests?

开发者 https://www.devze.com 2022-12-29 05:04 出处:网络
I\'ve got, what I would consider, a simple test web site. A single page with a single button. Here is a copy of the source I\'m working with if you would like to download it and play with it.

I've got, what I would consider, a simple test web site. A single page with a single button.

Here is a copy of the source I'm working with if you would like to download it and play with it.

When that button is clicked, it creates a JavaScript timer that executes once a second. When the timer function is executed, An AJAX call is made to retrieve a text value. That text value is then placed into the DOM.

What's my problem?

IE Caching.

Crack open Task Manager and watch what happens to the iexplorer.exe process (IE 8.0.7600.16385 for me) while the timer in that page is executing.

See the memory and handle count getting larger?

alt text http://www.joshuahayworth.com/content/HandleCount.png

Why is that happening when, by all accounts, I have caching turned off. I've got the jQuery cache option set to false in $.ajaxSetup. I've got the CacheControl header set to no-cache and no-store. The Expires header is set to DateTime.Now.AddDays(-1). The headers are set in both the page code-behind as well as 开发者_Go百科the HTTP Handler's response.

Anybody got any ideas as to how I could prevent IE from caching the results of the AJAX call?

Here is what the iexplorer.exe process looks like in ProcessMonitor. I believe that the activity shown in this picture is exactly what I'm attempting to prevent.

alt text http://www.joshuahayworth.com/content/ProcessMonitor.png


When you tell the browser not to cache the object, you're not saying "don't save this to disk", you're saying "do whatever, but don't use it again." The handles number you see is file handles, just because it's not being used for cache doesn't mean a file wasn't written and a handle to go along with it.

What you're telling IE is when you ask for that url again, that file you saved isn't a valid result for it...so go get it again, but that doesn't have anything to do with it being saved the first time.

The only issue you're seeing is IE not letting go of those file handles quickly...well that's IE, I can't explain the inner workings there. Perhaps someone else can shed some light?


Can't really shed any light on the internals of IE, or the growing memory and handle count, but a potential quick and dirty fix would be to put in a varying parameter to the ajax call, maybe based on your timer, or ticks from the current time.

Something along the lines of ...handler.axd?foo=varying_value_here

HTH

0

精彩评论

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