懒加载:当文件使用时才加载
预加载Prefetch:会在使用前提前加载js文件
正常加载可以认为是并行加载(同一时间加载多个文件)
预加载Prefetch:等其他资源加载完毕,浏览器空闲了,再偷偷加载 兼容性差
index.js
console.log('index.js被加载了')document.getElementById('btn').onclick = function(){import(/*webpackChunkName:'test',webpackPrefetch:true*/'./test').then(({mul})=>{console.log(mul(4,5))})}
test.js
console.log('test.js被加载了')export function mul(x, y) {return x * y;}
