Skip to content

Instantly share code, notes, and snippets.

@pgailloud
pgailloud / include.js
Created January 7, 2019 16:00 — forked from adrienjoly/include.js
native code to include a javascript / css file dynamically in a html document
function include(src){
return new Promise((resolve, reject) => {
var ext = src.split(/[\#\?]/)[0].split(".").pop().toLowerCase();
var inc;
if (ext == "js") {
inc = document.createElement("script");
inc.src = src;
inc.onerror = () => reject();
inc.onload = inc.onreadystatechange = () => resolve();
}