[Alternative Solution] Always use absolute URLs for cache keys and in state objects - Fixes #333 Closes #334 #336

merged 1 commit into from Feb 9, 2014


None yet

3 participants


@k1w1 Your fix (#334) has the right idea, but it won't work when traversing the browser history. When you hit the back button and cacheCurrentPage is called, document.location.href has already changed to the new URL. So you'll end up with a page cached with the wrong key. Try out my solution and let me know if it works for you.

@dhh I also did a bit of refactoring to clean up and organize the code. Does it look good to you?

@dhh dhh and 1 other commented on an outdated diff Feb 9, 2014
reflectRedirectedUrl = ->
if location = xhr.getResponseHeader 'X-XHR-Redirected-To'
- preservedHash = if removeHash(location) is location then document.location.hash else ''
- window.history.replaceState currentState, '', location + preservedHash
+ location = new ComponentUrl location
+ preservedHash = if location.withoutHash() is location.href then document.location.hash else ''
dhh Feb 9, 2014

Could abstract to if location.hasNoHash() then document.location.hash else ''

reed Feb 9, 2014

Yeah, that crossed my mind too, but I left it out in order to simplify the PR. But since you're on board, I'll add it back in.

dhh commented Feb 9, 2014

Looks OK to me!

@reed reed Refactor click handling, link checking, and url parsing into classes;…
… ensure absolute urls used for cache keys and state objects.
@reed reed merged commit 417a9d5 into turbolinks:master Feb 9, 2014

checking for the name of the constructor breaks when using uglifier to compress in the rails asset pipeline. This is because the class name of CompnentUrl is minified while the string is not changed. This means that when a component url is passed in from fetch -> reflectNewUrl it gets double converted into a ComponentUrl and breaks the url passed to window.history.pushState


Same issue as with ComponentUrl when used with uglifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment