A function written in JS is used to control the dynamic loading of JS files, that is, JS files are loaded only when needed, and CSS files can also be loaded, so that web pages can be reskinned. I think this function is well written. , take a serious look at it, you can see that it’s still quite good despite improving it.
function $import(path,type,title){
var s,i;
if(!type) type=path.substr(path.lastIndexOf(".") 1);
if(type=="js"){
var ss=document.getElementsByTagName("script");
for(i=0;i
If(ss[i].src && ss[i].src.indexOf(path)!=-1 || ss[i].title==title)return ss[i];
}
s=document.createElement("script");
s.type="text/javascript";
s.src=path;
If(title) s.title=title;
}
else if(type=="css"){
var ls=document.getElementsByTagName("link");
for(i=0;i
If(ls[i].href && ls[i].href.indexOf(path)!=-1 || ls[i].title==title)return ls[i];
}
s=document.createElement("link");
s.rel="stylesheet";
s.type="text/css";
s.href=path;
If(title) s.title=title;
s.disabled=false;
}
else return;
var head=document.getElementsByTagName("head")[0];
head.appendChild(s);
return s;
}