From 1378886fe042d17cab6281dfea2fbd492b8b191c Mon Sep 17 00:00:00 2001 From: artemave Date: Fri, 18 Apr 2014 20:52:14 +0200 Subject: [PATCH] Cache dom before leaving the page, rather than right after loding This way dynamically added dom (vis js) also gets cached. --- js/push.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/push.js b/js/push.js index 6aa5398..0853ff8 100644 --- a/js/push.js +++ b/js/push.js @@ -42,7 +42,6 @@ } cacheMapping[data.id] = JSON.stringify(data); window.history.replaceState(data.id, data.title, data.url); - domCache[data.id] = document.body.cloneNode(true); }; var cachePush = function () { @@ -60,7 +59,7 @@ delete cacheMapping[cacheBackStack.shift()]; } - window.history.pushState(null, '', cacheMapping[PUSH.id].url); + window.history.pushState(null, '', getCached(PUSH.id).url); cacheMapping.cacheForwardStack = JSON.stringify(cacheForwardStack); cacheMapping.cacheBackStack = JSON.stringify(cacheBackStack); @@ -243,6 +242,8 @@ }); } + cacheCurrentContent(); + if (options.timeout) { options._timeout = setTimeout(function () { xhr.abort('timeout'); }, options.timeout); } @@ -254,6 +255,10 @@ } }; + function cacheCurrentContent() { + domCache[PUSH.id] = document.body.cloneNode(true); + } + // Main XHR handlers // =================