From aef8e63cf8c00845155ff94371efbb559efdfac9 Mon Sep 17 00:00:00 2001 From: natecain Date: Tue, 1 Oct 2013 17:35:47 -0400 Subject: [PATCH 1/2] Use Blob api to generate data links in download saver This should fix crashing on large wikis under chrome see chrome bug: https://code.google.com/p/chromium/issues/detail?id=103234 This should also speed up generating the download html by a couple of seconds it avoids repeatedly marshalling the base64 encoded href string across the sandbox boundary it avoids some time and memory consumed by "large" dom manipulation major remaining delay is in encodeURIComponent TODO: consider using iconv on the server TODO: consider async invocation of regular expressions to avoid client "lockup" Conflicts: core/modules/savers/download.js --- core/modules/savers/download.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/modules/savers/download.js b/core/modules/savers/download.js index 623285561..d0d7e6989 100644 --- a/core/modules/savers/download.js +++ b/core/modules/savers/download.js @@ -28,7 +28,12 @@ DownloadSaver.prototype.save = function(text) { // Set up the link var link = document.createElement("a"); link.setAttribute("target","_blank"); - link.setAttribute("href","data:text/html," + encodeURIComponent(text)); + if(Blob != undefined) { + var blob = new Blob([encodeURIComponent(text)], {type: "text/html"}); + link.setAttribute("href", URL.createObjectURL(blob)); + } else { + link.setAttribute("href","data:text/html," + encodeURIComponent(text)); + } link.setAttribute("download",filename); document.body.appendChild(link); link.click(); From c45f4d1c626c63a1ed718d759b94727de84b12ea Mon Sep 17 00:00:00 2001 From: natecain Date: Tue, 17 Sep 2013 15:15:38 -0400 Subject: [PATCH 2/2] Small revision to previous commit, avoids double encoding. We don't need to encodeURIComponent at all when using blob links. The data never goes into the dom directly, just a guid reference. This makes saving with blobs very fast! --- core/modules/savers/download.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/savers/download.js b/core/modules/savers/download.js index d0d7e6989..7e10e188d 100644 --- a/core/modules/savers/download.js +++ b/core/modules/savers/download.js @@ -29,7 +29,7 @@ DownloadSaver.prototype.save = function(text) { var link = document.createElement("a"); link.setAttribute("target","_blank"); if(Blob != undefined) { - var blob = new Blob([encodeURIComponent(text)], {type: "text/html"}); + var blob = new Blob([text], {type: "text/html"}); link.setAttribute("href", URL.createObjectURL(blob)); } else { link.setAttribute("href","data:text/html," + encodeURIComponent(text));