Skip to content

Commit

Permalink
Merge pull request turbolinks#8 from jmbejar/skip-preview
Browse files Browse the repository at this point in the history
Add option to skip cache version in links
  • Loading branch information
sstephenson committed Mar 4, 2016
2 parents 93f56a1 + ffc125c commit 9ec9807
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/turbolinks/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ class Turbolinks.Controller
getCachedSnapshotForLocation: (location) ->
@cache.get(location)

shouldCacheSnapshot: ->
@getSetting("cache-control") isnt "no-cache"

cacheSnapshot: ->
@notifyApplicationBeforeCachingSnapshot()
snapshot = @view.getSnapshot()
@cache.put(@lastRenderedLocation, snapshot)
if @shouldCacheSnapshot()
@notifyApplicationBeforeCachingSnapshot()
snapshot = @view.getSnapshot()
@cache.put(@lastRenderedLocation, snapshot)

# Scrolling

Expand Down
6 changes: 6 additions & 0 deletions src/turbolinks/snapshot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Turbolinks.Snapshot
getTemporaryHeadElements: ->
@getTemporaryHeadElementSet().getElements()

isPreviewable: ->
@getCacheControlValue() isnt "no-preview"

# Private

getTrackedHeadElementSet: ->
Expand All @@ -55,3 +58,6 @@ class Turbolinks.Snapshot
getHeadElementSet: ->
@headElementSet ?= new Turbolinks.ElementSet @head.childNodes

getCacheControlValue: ->
[..., element] = @head.querySelectorAll("meta[name='turbolinks-cache-control']")
element?.getAttribute("content")
7 changes: 4 additions & 3 deletions src/turbolinks/visit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class Turbolinks.Visit
@request.send()

getCachedSnapshot: ->
snapshot = @controller.getCachedSnapshotForLocation(@location)
return if @location.anchor? and not snapshot?.hasAnchor(@location.anchor)
snapshot
if snapshot = @controller.getCachedSnapshotForLocation(@location)
if not @location.anchor? or snapshot.hasAnchor(@location.anchor)
if @action is "restore" or snapshot.isPreviewable()
snapshot

hasCachedSnapshot: ->
@getCachedSnapshot()?
Expand Down

0 comments on commit 9ec9807

Please sign in to comment.