Reputation: 1573
I tested Chrome (linux and windows), Firefox, and Opera.
Every time I do a pushState, Chrome is going to the server. It doesn't seem to use the request in any way, I only noticed it because I was watching 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 isn't even the URL that is being pushed.
Firefox and Opera don't do this, and it seems like incorrect behavior to me. Is is a bug?
The reason I worry is for scaling. I don't want users making dummy requests while they are browsing my app.
Upvotes: 4
Views: 460
Reputation: 1891
@JavascriptNewbie - You are not alone :D
Congratulations on being the only other ruddy person on the planet (or the internets at least) to have noticed this and to be proficient enough to actually check your stinking logs.
The Good: Chrome and Firefox can do that prefetch when they please and sometimes do it with pushState to make back/forward better. It looks like in your case at least it is aborting the "prerender" due to something in your page... but you might want to check that to see if it is also pre-fetching and executing your linked scripts or styles.
The Short: Chrome and FireFox may decide to fetch the pushState/replaceState url from the server in order to be able to optimize their back/forward caching and in case the person copies and pastes the url from the nav bar. This is non-deterministic and does not always happen.
The Long: It gets worse, unless you hit one of the constraints mentioned here: https://developers.google.com/chrome/whitepapers/prerender Chrome will actually interpret and execute your javascripts... which could trigger things like AJAX, and even Websockets.
The Longer: I've done a test suite and writeup here: https://github.com/nickhsharp/prefetchNightmare which may eventually get itself a blog post.
Upvotes: 8