Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #193 from benweint/add-page-received

  • Loading branch information...
commit 7d4238f2deafbccc8e40be07ef7d2197890ec941 2 parents 61e92f5 + e74ed4b
@reed reed authored
Showing with 3 additions and 0 deletions.
  1. +1 −0  README.md
  2. +2 −0  lib/assets/javascripts/turbolinks.js.coffee
View
1  README.md
@@ -33,6 +33,7 @@ Since pages will change without a full reload with Turbolinks, you can't by defa
* `page:load` fetched page is being retrieved fresh from the server.
* `page:restore` fetched page is being retrieved from the 10-slot client-side cache.
* `page:change` page has changed to the newly fetched version.
+* `page:receive` page has been fetched from the server, but not yet parsed.
So if you wanted to have a client-side spinner, you could listen for `page:fetch` to start it and `page:change` to stop it. If you have DOM transformation that are not idempotent (the best way), you can hook them to happen only on `page:load` instead of `page:change` (as that would run them again on the cached pages).
View
2  lib/assets/javascripts/turbolinks.js.coffee
@@ -29,6 +29,8 @@ fetchReplacement = (url) ->
xhr.setRequestHeader 'X-XHR-Referer', referer
xhr.onload = =>
+ triggerEvent 'page:receive'
+
if invalidContent(xhr) or assetsChanged (doc = createDocument xhr.responseText)
document.location.reload()
else
Please sign in to comment.
Something went wrong with that request. Please try again.