File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 66 var fontFaces = newFontFaces ( ) ;
77 var images = newImages ( ) ;
88
9+ var cacheForResponses = [ ] ;
10+
911 // Default impl options
1012 var defaultOptions = {
1113 // Default is to fail on error, no placeholder
495497
496498 function getAndEncode ( url ) {
497499 var TIMEOUT = 30000 ;
500+ var _url = url . split ( '?' ) [ 0 ] ;
501+ var _obj = cacheForResponses . find ( function ( el ) {
502+ return el . url === _url ;
503+ } ) ;
504+ if ( _obj ) return _obj . promise ;
505+
498506 if ( domtoimage . impl . options . cacheBust ) {
499507 // Cache bypass so we dont have CORS issues with cached images
500508 // Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
501509 url += ( ( / \? / ) . test ( url ) ? "&" : "?" ) + ( new Date ( ) ) . getTime ( ) ;
502510 }
503511
504- return new Promise ( function ( resolve ) {
512+ var promise = new Promise ( function ( resolve ) {
505513 var request = new XMLHttpRequest ( ) ;
506514
507515 request . onreadystatechange = done ;
553561 resolve ( '' ) ;
554562 }
555563 } ) ;
564+ _obj = {
565+ url : _url ,
566+ promise : promise
567+ } ;
568+ cacheForResponses . push ( _obj ) ;
569+ return _obj . promise ;
556570 }
557571
558572 function dataAsUrl ( content , type ) {
You can’t perform that action at this time.
0 commit comments