异步加载JSCSS

Posted 欧文凌志

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异步加载JSCSS相关的知识,希望对你有一定的参考价值。

function AsyncLoad(V_tag,V_src)
{
if (V_tag == "script") {
var s = document.createElement(‘script‘);
s.type = ‘text/javascript‘;
s.async = true;
s.src = V_src;
var x = document.getElementsByTagName(‘script‘)[0];
x.parentNode.insertBefore(s, x);
s.onload = function () {
if (V_src == "../Content/Scripts/jquery-2.1.1.min.js") {
AsyncLoad("script", "../Content/Scripts/public-effect.js");
AsyncLoad("script", "../Content/Scripts/d3.v3.min.js");

AsyncLoad("script", "../Content/Scripts/Common.js");

AsyncLoad("script", "../Content/Scripts/mobilePie.js");
}
if (V_src == "../Content/Scripts/d3.v3.min.js")
{
AsyncLoad("script", "../Content/Scripts/Ticket/MyPCs.js");
}
}
} else {
var s = document.createElement(‘link‘);
s.async = true;
s.rel = "stylesheet"
s.href = V_src;
var x = document.getElementsByTagName(‘link‘)[0];
x.parentNode.insertBefore(s, x);
s.onload = function () {
}
}
}
window.onload = function () {
AsyncLoad("link", "../Content/stylesheets/swiper-3.2.7.min.css");
AsyncLoad("script", "../Content/Scripts/jquery-2.1.1.min.js");
AsyncLoad("script", "../Content/Scripts/swiper-3.2.7.jquery.min.js");

}

以上是关于异步加载JSCSS的主要内容,如果未能解决你的问题,请参考以下文章

js怎么异步加载loading

seajs.use为异步加载吗

如何在vue3中通过点击按钮异步加载组件

Vue中router路由异步加载组件-优化性能

Unity异步加载关卡

iOS 异步加载图片 使用EGOImageView、SDWebImage按步骤使用的,就是不能显示图片