Ticket #11611 (closed bug: patchwelcome)
on IE8 `cache: false` needs to be obeyed in all ajax requests or maybe even forced
| Reported by: | walde.christian@… | Owned by: | jaubourg |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | ajax | Version: | 1.7.1 |
| Keywords: | Cc: | jaubourg | |
| Blocking: | Blocked by: |
Description
The problem is at this position:
https://github.com/jquery/jquery/blob/master/src/ajax.js#L664
This line skips the logic triggered by cache: false if the request type is anything but HEAD or GET. I assume this is done for optimization, because most browsers won't cache on other types of requests.
However IE8 does not play by those rules.
I was in this situation:
host.tld/foo was first loaded as a normal GET request via the browser address bar. Modifications to the server session were then done via other ajax requests. Finally a POST request without any parameters was done to host.tld/foo, which would normally start processing of the data in the server session.
IE8 however did not even hit the server and instead delivered the cache of the GET request to host.tld/foo to jquery's ajax function, which expected a JSON reply and simply threw a "Syntax Error" when faced with HTML.
Normally this would be fixed easily with cache: false, but since that option is ignored on requests other than HEAD or GET i had to modify the url manually, which resolved the situation. As such, the logic should be modified to either of these options:
- obey cache option on all request types
- obey cache option on all request types in IE8
- force cache option on all request types in IE8
Personally i would prefer c., since it would transparently work around this IE bug for other users, but i do not know how feasible it is.
Note: This is with a real IE8 on WinXP, not IE9 in compatibility mode.
Change History
comment:2 Changed 13 months ago by rwaldron
- Owner set to jaubourg
- Priority changed from undecided to low
- Status changed from new to assigned
- Component changed from unfiled to ajax
- Milestone changed from None to 1.next
comment:3 follow-up: ↓ 5 Changed 13 months ago by jaubourg
- Status changed from assigned to closed
- Resolution set to patchwelcome
If we change current behaviour code will break in the wild. I think the best solution is for the poster to use the workaround he's actually using. This is quite the edge case if you ask me.If we cater for IE8 here, then we screw all the others. Unless there is a way to feature-test this (which is highly unlikely), I don't see it as fixable in a generic fashion.
comment:4 Changed 13 months ago by gibson042
Would anything break if we moved the anti-cache logic out of the !s.hasContent block? It seems like that would resolve this ticket, and anyone explicitly setting cache: false probably expects an effect.
comment:5 in reply to: ↑ 3 Changed 13 months ago by Mithaldu
Replying to jaubourg:
If we change current behaviour code will break in the wild.
I challenge this assumption. I can not think of any possible way that making POST ajax requests observe the cache setting (instead of silently ignoring it) would break anything at all.
Can you provide any example of how any breakage would result from this?
comment:6 Changed 13 months ago by jaubourg
$.post( "myUrl" ) => myUrl?anticacheparam=anticachevalue
I call that breaking to say the least when cache:false does set anti-cache headers (wich IS an effect). This IS a IE8 bug and trying to fix it without feature-testing is a call for disaster. And we cannot feature-test this kind of things... you're welcome to try though, but don't blame me if you end up as cynical as I am after a single year of ajax maintenance ;P
Challenge all you want: it has been proven time and time again that changing the most insignificant part of jQuery's behaviour breaks a massive amount of code and this is NOT insignificant.
Replying to gibson042:
Would anything break if we moved the anti-cache logic out of the !s.hasContent block? It seems like that would resolve this ticket, and anyone explicitly setting cache: false probably expects an effect.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I don't think it was there as an optimization, it's more likely we didn't anticipate someone would GET and POST to the same URL that way. It seems like the POST needs the cache buster, which would be option a in your list I think.
@jaubourg, what do you think?