diff --git a/public/index.html b/public/index.html index 6dfba9f..2d40aca 100644 --- a/public/index.html +++ b/public/index.html @@ -638,6 +638,7 @@ nodePageContent: null, nodePageProgress: 0, nodePagePathHistory: [], + nodePageCache: {}, isDownloadingNodeFile: false, nodeFilePath: null, @@ -1162,7 +1163,7 @@ // do nothing if failed to load messages } }, - async loadNodePage(destinationHash, pagePath, addToHistory = true) { + async loadNodePage(destinationHash, pagePath, addToHistory = true, loadFromCache = true) { // get new sequence for this page load const seq = ++this.nodePageRequestSequence; @@ -1181,6 +1182,22 @@ this.nodePagePathHistory.push(previousNodePagePath); } + // check if we can load this page from the cache + if(loadFromCache){ + + // load from cache + const nodePagePathCacheKey = `${destinationHash}:${pagePath}`; + const cachedNodePageContent = this.nodePageCache[nodePagePathCacheKey]; + + // if page is cache, we can just return it now + if(cachedNodePageContent != null){ + this.nodePageContent = cachedNodePageContent; + this.isLoadingNodePage = false; + return; + } + + } + this.downloadNomadNetPage(destinationHash, pagePath, (pageContent) => { // do nothing if callback is for a previous request @@ -1197,6 +1214,10 @@ this.nodePageContent = pageContent; } + // update cache + const nodePagePathCacheKey = `${destinationHash}:${pagePath}`; + this.nodePageCache[nodePagePathCacheKey] = this.nodePageContent; + // update page content this.isLoadingNodePage = false; @@ -1227,8 +1248,8 @@ }, async reloadNodePage() { - // reload current node page without adding to history - this.onNodePageUrlClick(this.nodePagePath, false); + // reload current node page without adding to history and without using cache + this.onNodePageUrlClick(this.nodePagePath, false, false); }, async loadPreviousNodePage() { @@ -1281,7 +1302,7 @@ return null; }, - onNodePageUrlClick: function(url, addToHistory = true) { + onNodePageUrlClick: function(url, addToHistory = true, useCache = true) { // open http urls in new tab if(url.startsWith("http://") || url.startsWith("https://")){ @@ -1342,7 +1363,7 @@ }; // navigate to node page - this.loadNodePage(destinationHash, parsedUrl.path, addToHistory); + this.loadNodePage(destinationHash, parsedUrl.path, addToHistory, useCache); return; }