babel-plugin-universal-import
Advanced tools
Comparing version 1.3.4 to 1.4.0
@@ -35,3 +35,2 @@ /* eslint-disable */ | ||
link.href = href | ||
link.charset = 'utf-8' | ||
@@ -44,3 +43,18 @@ link.type = 'text/css' | ||
var timeout | ||
var img | ||
var onload = function() { | ||
// Check if we created the img tag. | ||
// If we did then the chunk was loaded via img.src | ||
// and we need to set the link.href which will then | ||
// load the resource from cache | ||
if (img) { | ||
link.href = href | ||
img.onerror = null // avoid mem leaks in IE. | ||
} | ||
link.onerror = null // avoid mem leaks in IE. | ||
clearTimeout(timeout) | ||
resolve() | ||
} | ||
link.onerror = function() { | ||
@@ -53,9 +67,14 @@ link.onerror = link.onload = null // avoid mem leaks in IE. | ||
// link.onload doesn't work well enough, but this will handle it | ||
// since images can't load css (this is a popular fix) | ||
var img = document.createElement('img') | ||
img.onerror = function() { | ||
link.onerror = img.onerror = null // avoid mem leaks in IE. | ||
clearTimeout(timeout) | ||
resolve() | ||
if (isOnloadSupported() && 'onload' in link) { | ||
link.onload = onload | ||
link.href = href | ||
} else { | ||
// Use img.src as a fallback to loading the css chunk in browsers | ||
// which don’t support link.onload | ||
// We use the img.onerror handler because an error will always fire | ||
// when parsing the response | ||
// Then we know the resource has been loaded | ||
img = document.createElement('img') | ||
img.onerror = onload | ||
img.src = href | ||
} | ||
@@ -65,3 +84,2 @@ | ||
head.appendChild(link) | ||
img.src = href | ||
}) | ||
@@ -74,1 +92,20 @@ } | ||
} | ||
// Checks whether the browser supports link.onload | ||
// Reference: https://pie.gd/test/script-link-events/ | ||
function isOnloadSupported() { | ||
var userAgent = navigator.userAgent | ||
var supportedMajor = 535 | ||
var supportedMinor = 24 | ||
var match = userAgent.match(/\ AppleWebKit\/(\d+)\.(\d+)/) | ||
if (match) { | ||
var major = +match[1] | ||
var minor = +match[2] | ||
return ( | ||
(major === supportedMajor && minor >= supportedMinor) || | ||
major > supportedMajor | ||
) | ||
} | ||
// All other browsers support it | ||
return true | ||
} |
{ | ||
"name": "babel-plugin-universal-import", | ||
"version": "1.3.4", | ||
"version": "1.4.0", | ||
"description": "Babel plugin to transform import() into its Universal counterpart", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
411351
780