Skip to content

Commit

Permalink
https://github.com/tsayen/dom-to-image/pull/336
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Burzec committed Sep 17, 2020
1 parent 6f4d99a commit 47e8188
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/dom-to-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
var fontFaces = newFontFaces();
var images = newImages();

var cacheForResponses = [];

// Default impl options
var defaultOptions = {
// Default is to fail on error, no placeholder
Expand Down Expand Up @@ -495,13 +497,19 @@

function getAndEncode(url) {
var TIMEOUT = 30000;
var _url = url.split('?')[0];
var _obj = cacheForResponses.find(function (el) {
return el.url === _url;
});
if (_obj) return _obj.promise;

if(domtoimage.impl.options.cacheBust) {
// Cache bypass so we dont have CORS issues with cached images
// Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
url += ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
}

return new Promise(function (resolve) {
var promise = new Promise(function (resolve) {
var request = new XMLHttpRequest();

request.onreadystatechange = done;
Expand Down Expand Up @@ -553,6 +561,12 @@
resolve('');
}
});
_obj = {
url: _url,
promise: promise
};
cacheForResponses.push(_obj);
return _obj.promise;
}

function dataAsUrl(content, type) {
Expand Down

0 comments on commit 47e8188

Please sign in to comment.