vite-plugin-light-view
用于vite打包的插件
描述
🐛
解决问题 在单页应用中资源文件可能懒加载,用于提前加载资源文件,使用时直接304使用缓存。防止网络冷启动的卡顿
实现过程
在vite打包完成的钩子中 ,递归扫描dist文件夹生成资源数组字符串,创建预获取文件的js,使用vite-plugin-parse-html
的injec
t函数往index.html
添加sources
。页面启动时自动加载脚本。
实战
- 使用
- 效果
🤔
思考 目前使用script
标签的方式预获取 不太优雅,还可以使用web worker的方式,请求记录会出现在 网络调试工具fetch/xhr里面