     visit link.href
     event.preventDefault()
 
+rememberInitialPage = ->
+  window.history.replaceState { turbolinks: true, position: window.history.length - 1}, "", document.location.href
+  lastState = window.history.state
 
 browserSupportsPushState = window.history and window.history.pushState and window.history.replaceState
 
 if browserSupportsPushState
+  rememberInitialPage()
   window.addEventListener 'popstate', (event) ->
     if event.state?.turbolinks
       fetchHistory event.state

  replaceDocument doc.body,title?.textContent, 'cache'


replaceDocument = (body,title,cache) ->
  originalBody = document.body
  document.documentElement.appendChild body, originalBody
  document.documentElement.removeChild originalBody
  document.title = title
  historyCache[window.history.state.position] = {url:document.location.href,body:body,title:title} if cache



extractLink = (event) ->

  xhr.send()

fetchHistory = (state) ->
  rememberPage()
  cache = historyCache[state.position]
  if cache
    replaceDocument cache.body, cache.title
    triggerPageChange
    window.scrollTo(cache.pageXOffset,cache.pageYOffset)
  else
    fetchReplacement document.location.href

