Skip to content

Instantly share code, notes, and snippets.

@poltorrr
Created August 14, 2020 17:35
load script
<script>
function loadScript(url, callback) {
let selector = 'script[src*="' + url + '"]';
if (!document.querySelector(selector)) {
let script = document.createElement("script");
script.type = 'text/javascript';
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState === 'loaded' ||
script.readyState === 'complete') {
script.onreadystatechange = null;
if (callback) {
callback();
}
}
};
} else { //Others
script.onload = function () {
if (callback) {
callback();
}
};
}
script.src = url;
document.body.appendChild(script);
}
}
loadScript('js/vendor/jquery-3.5.1.min.js', () => {
consol.log('loaded')
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment