@zodash/load-script
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.1.4](https://github.com/zcorky/zodash/compare/@zodash/load-script@0.1.3...@zodash/load-script@0.1.4) (2020-11-26) | ||
**Note:** Version bump only for package @zodash/load-script | ||
## 0.1.3 (2020-11-11) | ||
@@ -8,0 +16,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usingFetch = exports.usingAjax = exports.loadScript = void 0; | ||
const cache = new Map(); | ||
function loadScript(path) { | ||
return new Promise((resolve, reject) => { | ||
if (cache.get(path)) { | ||
return resolve(); | ||
} | ||
const script = document.createElement('script'); | ||
@@ -11,3 +15,4 @@ script.src = path; | ||
script.onload = () => { | ||
resolve(); | ||
cache.set(path, true); | ||
return resolve(); | ||
}; | ||
@@ -20,2 +25,5 @@ document.head.appendChild(script); | ||
return new Promise((resolve, reject) => { | ||
if (cache.get(path)) { | ||
return resolve(); | ||
} | ||
const xhr = new XMLHttpRequest(); | ||
@@ -28,3 +36,6 @@ xhr.onreadystatechange = function () { | ||
document.head.appendChild(script); | ||
setTimeout(resolve, 0); | ||
setTimeout(() => { | ||
cache.set(path, true); | ||
return resolve(); | ||
}, 0); | ||
} | ||
@@ -40,2 +51,5 @@ }; | ||
return new Promise((resolve, reject) => { | ||
if (cache.get(path)) { | ||
return resolve(); | ||
} | ||
return fetch(path) | ||
@@ -48,3 +62,6 @@ .then(res => res.text()) | ||
document.head.appendChild(script); | ||
setTimeout(resolve, 0); | ||
setTimeout(() => { | ||
cache.set(path, true); | ||
return resolve(); | ||
}, 0); | ||
}); | ||
@@ -51,0 +68,0 @@ }); |
{ | ||
"name": "@zodash/load-script", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Dynamic load script", | ||
@@ -68,3 +68,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "fb0b997fc51fbad9866a754bf8609d0bcc962700" | ||
"gitHead": "1e8662170d99de2cfd4095e1cdbb0f6e89fd4d49" | ||
} |
Sorry, the diff of this file is not supported yet
7996
68