@@ -338,11 +338,22 @@ class MiniCssExtractPlugin {
338
338
] ) ,
339
339
'}' ,
340
340
'var linkTag = document.createElement("link");' ,
341
- 'var isOldWebKit = Number(navigator.userAgent.replace(/.*AppleWebKit\\/(\\d+)..*/, "$1")) < 536;' ,
342
341
'linkTag.rel = "stylesheet";' ,
343
342
'linkTag.type = "text/css";' ,
344
- 'if (!isOldWebKit) {' ,
345
- 'linkTag.onload = resolve;' ,
343
+ 'linkTag.href = fullhref;' ,
344
+ "// old webkit's would claim to have onload, but didn't really support it" ,
345
+ '// https://github.com/kriszyp/xstyle/blob/master/core/load-css.js' ,
346
+ 'var webkitVersion = navigator.userAgent.match(/AppleWebKit\\/(\\d+\\.?\\d*)/);' ,
347
+ 'webkitVersion = webkitVersion && +webkitVersion[1];' ,
348
+ 'if(linkTag.onload === null && !(webkitVersion < 536)){' ,
349
+ '// most browsers support this onload function now' ,
350
+ 'linkTag.onload = function(){' ,
351
+ '// cleanup' ,
352
+ 'linkTag.onload = null;' ,
353
+ 'linkTag.onerror = null;' ,
354
+ 'resolve();' ,
355
+ '};' ,
356
+ '// always add the error handler, so we can notify of any errors' ,
346
357
'linkTag.onerror = function(event) {' ,
347
358
Template . indent ( [
348
359
'var request = event && event.target && event.target.src || fullhref;' ,
@@ -351,11 +362,27 @@ class MiniCssExtractPlugin {
351
362
'reject(err);' ,
352
363
] ) ,
353
364
'};' ,
365
+ '} else {' ,
366
+ 'var errorTimeout = 60000;' ,
367
+ 'var startTime = Date.now();' ,
368
+ 'var interval = setInterval(function(){' ,
369
+ 'if(linkTag.style){' ,
370
+ 'clearInterval(interval);' ,
371
+ 'resolve();' ,
372
+ '}' ,
373
+ 'if(!linkTag.style && (Date.now() - startTime) > errorTimeout){' ,
374
+ Template . indent ( [
375
+ 'var request = fullhref;' ,
376
+ 'var err = new Error("Loading CSS chunk " + chunkId + " timeout in old browser.\\n(" + request + ")");' ,
377
+ 'err.request = request;' ,
378
+ 'clearInterval(interval);' ,
379
+ 'reject(err);' ,
380
+ ] ) ,
381
+ '}' ,
382
+ '}, 25);' ,
354
383
'}' ,
355
- 'linkTag.href = fullhref;' ,
356
384
'var head = document.getElementsByTagName("head")[0];' ,
357
385
'head.appendChild(linkTag);' ,
358
- 'if (isOldWebKit) { resolve();}' ,
359
386
] ) ,
360
387
'}).then(function() {' ,
361
388
Template . indent ( [ 'installedCssChunks[chunkId] = 0;' ] ) ,
0 commit comments