Why is Google Chrome sent to the server on pushState?

I tested Chrome (linux and windows), Firefox and Opera.

Every time I do pushState, Chrome goes to the server. It does not seem to use the request in any way, I noticed this only because I was looking at the log file.

Here is the request:

16 Mar 2013 01:00 PM ip=127.0.0.1 agent=Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22 uri=/ T1=0ms T2=0ms T3=0ms 

Here is the line of code:

 history.pushState({}, 'my_app', URL); 

I know the URI says '/', but that is not even the URL that is being called.

Firefox and Opera do not, and it seems to me the wrong behavior. Is there a mistake?

I worry about scaling. I do not want users to make dummy requests when they view my application.

+4
source share
1 answer

@JavascriptNewbie - You're Not Alone: ​​D

Congratulations on the fact that I was the only other ruddy person on the planet (or at least in boarding schools) to notice this and understand well enough to really check your smelly magazines.

The Good: Chrome and Firefox can do this prefetch whenever they want, and sometimes do it with pushState to do a better back / forward. It looks like in your case, at least this is a "prerender" interrupt due to something on your page ... but you can check this to make sure it also prefetch and executes your associated scripts or styles .

Short: Chrome and FireFox may decide to get the pushState / replaceState URL from the server in order to be able to optimize caching in the back / forward mode if the person copies and pastes the URL from the navigation bar. This is not deterministic and does not always occur.

The Long: It gets worse if you don’t click on one of the restrictions mentioned here: https://developers.google.com/chrome/whitepapers/prerender Chrome will actually interpret and execute your javascripts ... that can cause things like AJAX, and even Websockets.

The Longer: I made a test suite and wrote here: https://github.com/nickhsharp/prefetchNightmare , which may end up with a blog post.

+7
source

All Articles