   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) ->

@historyCache = []

visit = (url) ->
  if browserSupportsPushState? and document.location.href != url
    @historyCache.push({url:document.location.href,body:document.body,title:document.title})
    reflectNewUrl url
    fetchReplacement url
  else

browserSupportsPushState = window.history and window.history.pushState and window.history.replaceState

rememberInitialPage = ->
  window.history.replaceState { turbolinks: true, position: window.history.length - 1}, "", document.location.href
  historyCache[window.history.state.position] = {url:document.location.href,body:document.body,title:document.title}

if browserSupportsPushState
  document.addEventListener 'DOMContentLoaded', (event) ->
    rememberInitialPage()
  window.addEventListener 'popstate', (event) ->
    if event.state?.turbolinks
      fetchHistory event.state
  document.addEventListener 'click', (event) ->
    handleClick event

