提交 23690f57 编写于 作者: K Kevin Ngo

have fileloader merge multiple concurrent requests for the same url (fixes #10644)

上级 fdefb19b
...@@ -23,7 +23,7 @@ Object.assign( FileLoader.prototype, { ...@@ -23,7 +23,7 @@ Object.assign( FileLoader.prototype, {
var cached = Cache.get( url ); var cached = Cache.get( url );
if ( cached !== undefined ) { if ( cached !== undefined && ! cached.loaderSubscriptions ) {
scope.manager.itemStart( url ); scope.manager.itemStart( url );
...@@ -39,6 +39,19 @@ Object.assign( FileLoader.prototype, { ...@@ -39,6 +39,19 @@ Object.assign( FileLoader.prototype, {
} }
// If file is already in process of loading, wait for it to load.
if ( cached !== undefined && cached.loaderSubscriptions ) {
cached.loaderSubscriptions.push( function () {
scope.load( url, onLoad, onProgress, onError );
} );
return;
}
// Check for data: URI // Check for data: URI
var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/; var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
var dataUriRegexResult = url.match( dataUriRegex ); var dataUriRegexResult = url.match( dataUriRegex );
...@@ -128,7 +141,12 @@ Object.assign( FileLoader.prototype, { ...@@ -128,7 +141,12 @@ Object.assign( FileLoader.prototype, {
} else { } else {
var loaderSubscriptions = [];
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
// Allow other file loaders to wait and subscribe on this request.
Cache.add( url, { loaderSubscriptions: loaderSubscriptions } );
request.open( 'GET', url, true ); request.open( 'GET', url, true );
request.addEventListener( 'load', function ( event ) { request.addEventListener( 'load', function ( event ) {
...@@ -163,6 +181,13 @@ Object.assign( FileLoader.prototype, { ...@@ -163,6 +181,13 @@ Object.assign( FileLoader.prototype, {
} }
// Tell other requests for the same file that the file has finished loading.
for ( var i = 0; i < loaderSubscriptions.length; i ++ ) {
loaderSubscriptions[ i ]( response );
}
}, false ); }, false );
if ( onProgress !== undefined ) { if ( onProgress !== undefined ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册