Web applications can be very powerful. With Ajax and CORS (Cross-Origin Resource Sharing) one can really do wonders. And that was exactly our case: we needed to outsource a small polling script, that would check the state every few seconds and figure out, whether a container should be reloaded via another Ajax request.
Worked like a charm in Firefox. And here comes a customer demo in Chrome – NOPE. Page does not load. Console is silent. Caching headers – set everywhere. Chrome still insists – “Ajax request pending”.
The solution we found is unfortunately not something that will work globally – but we are deploying the app for a limited audience, therefore it “kind of” works for us.
And sometimes it would take only 5 seconds – sometimes 50. Sometimes even longer. Google and Stackoverflow ideas – very helpful, but not effective.
What was the culprit? Chrome itself – and to be more specific – Chrome’s option to make browsing even faster! Namely: pre-rendering of web pages. Once this option was switched off it was impossible to reproduce the error. It worked like a charm every-single-time.
How to disable it? Go to Chrome Settings, and in advanced options under “Privacy” find a point called “Use a prediction service to load pages more quickly”. Disable it. That’s it, you are ready.
As it was said before – there are “two hard things in computer science: cache invalidation, naming things and off-by-one errors”.