目录
当前位置: 首页 > 文档资料 > Coolie 官方指南 >

异步模块

优质
小牛编辑
125浏览
2023-12-01

异步模块

if (isIE8) {
    require.async('compatible-ie8.js', function(exports){
        // ...
    });
} else if (isIE6) {
    require.async('compatible-ie6.js', function(exports){
        // ...
    });
} else {
    require.async('compatible-es5.js', function(exports){
        // ...
    });
}

这是很常见的需求。根据不同的情况,加载不同的模块。

如上,模块compatible-ie8.jscompatible-ie6.jscompatible-es5.js这 3 个模块 不会在页面同步载入,而是在代码运行到此处时才会异步加载。