Skip to content

Commit 6e6b02c

Browse files
authored
Cache: Don't cache Blobs. (mrdoob#32989)
1 parent e41978b commit 6e6b02c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/loaders/Cache.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const Cache = {
3535

3636
if ( this.enabled === false ) return;
3737

38+
if ( isBlobURL( key ) ) return;
39+
3840
// log( 'Cache', 'Adding key:', key );
3941

4042
this.files[ key ] = file;
@@ -52,6 +54,8 @@ const Cache = {
5254

5355
if ( this.enabled === false ) return;
5456

57+
if ( isBlobURL( key ) ) return;
58+
5559
// log( 'Cache', 'Checking key:', key );
5660

5761
return this.files[ key ];
@@ -83,5 +87,29 @@ const Cache = {
8387

8488
};
8589

90+
/**
91+
* Returns true if the given cache key contains the blob: scheme.
92+
*
93+
* @private
94+
* @param {string} key - The cache key.
95+
* @return {boolean} Whether the given cache key contains the blob: scheme or not.
96+
*/
97+
function isBlobURL( key ) {
98+
99+
try {
100+
101+
const urlString = key.slice( key.indexOf( ':' ) + 1 ); // remove type identifier
102+
103+
const url = new URL( urlString );
104+
return url.protocol === 'blob:';
105+
106+
} catch ( e ) {
107+
108+
// If the string is not a valid URL, it throws an error
109+
return false;
110+
111+
}
112+
113+
}
86114

87115
export { Cache };

0 commit comments

Comments
 (0)