   if browserSupportsPushState && browserIsntBuggy
     cacheCurrentPage()
     reflectNewUrl url
-    fetchReplacement url
+    needsRefresh
+      yes: ->
+        fetchReplacement url
+      no: ->
+        fetchFromLocalStore url
   else
     document.location.href = url
 


  xhr.send()

fetchHistory = (state) ->
  cacheCurrentPage()

  if page = pageCache[state.position]
    xhr?.abort()
    changePage page.title, page.body
    recallScrollPosition page
    triggerEvent 'page:restore'
  else
    fetchReplacement document.location.href


cacheCurrentPage = ->
  rememberInitialPage()


  xhr.onload = =>
    triggerEvent 'page:receive'

    if invalidContent(xhr) or assetsChanged (doc = createDocument xhr.responseText)
      document.location.reload()
    else
      # cache page in local store:
      localStorage.setItem(safeUrl, xhr.responseText)
      localStorage.setItem('etag-' + safeUrl, xhr.getResponseHeader('Etag'))

      changePage extractTitleAndBody(doc)
      reflectRedirectedUrl xhr
      if document.location.hash
        document.location.href = document.location.href
