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

  else
    createDocumentUsingWrite

replaceHTML = (html) ->
  doc = createDocument html
  originalBody = document.body
  document.documentElement.appendChild doc.body, originalBody
  document.documentElement.removeChild originalBody
  document.title = title.textContent if title = doc.querySelector "title"


extractLink = (event) ->

  xhr.onabort = -> console.log("Aborted turbolink fetch!")
  xhr.send()

fetchHistory = (url) ->
  while(historyCache.length > 0)
    cache = historyCache.pop()
    if cache.url == url
      replaceHTML cache.html
      triggerPageChange
      return

  fetchReplacement url

fullReplacement = (html, url) ->
  replaceHTML html, "cache"
  triggerPageChange()

reflectNewUrl = (url) ->
