Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax + pushState bug in Chrome

I've encountered a strange bug in Chrome 19. I implemented a full-AJAX website (every non-external link is opened via AJAX request) with pushState support. I transmit the HTML snippets in AJAX via JSON format.

When I leave my site via an external link and then go back, Chrome renders cached data for that URL - the problem is, he caches the JSON content and shows that, instead of full web-page.

This is reproducible by these steps (UPDATE: I removed AJAX functionality on my website since then, so this bug does no longer appear):

  1. Open http://beta.mirtes.cz/
  2. Click on the second date link (16. 6. 2012 next to "It all began with a strange e-mail"). This page (you are now at http://beta.mirtes.cz/it-all-began-with-a-strange-e-mail) is loaded via AJAX.
  3. Click on "It all began with a strange e-mail". You are redirected to an external website.
  4. Click "Back" in Chrome after the page is completely loaded.

I try to send all AJAX responses with Cache-Control: no-cache, but with no effect.

Firefox 12 works OK.

like image 545
Ondřej Mirtes Avatar asked Jun 15 '12 22:06

Ondřej Mirtes


1 Answers

I came with a workaround - I perform AJAX request with additional dummy GET parameter - ?ajax=1. This way the browser can recognize the difference between usual HTML content and JSON. It doesn't have any impact on the user, the parameter is visible only in Firebug.

like image 80
Ondřej Mirtes Avatar answered Jan 02 '23 07:01

Ondřej Mirtes