vite-plugin-light-view
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

vite-plugin-light-view

用于vite打包的插件

npm-image npm-download npm-size-image

描述

🛸 用于单页应用预获取JS资源文件

解决问题 🐛

在单页应用中资源文件可能懒加载,用于提前加载资源文件,使用时直接304使用缓存。防止网络冷启动的卡顿

实现过程

在vite打包完成的钩子中 ,递归扫描dist文件夹生成资源数组字符串,创建预获取文件的js,使用vite-plugin-parse-htmlinject函数往index.html添加sources。页面启动时自动加载脚本。

实战

  • 使用

图片 图片 图片

  • 效果

图片 图片 图片

思考 🤔

目前使用script标签的方式预获取 不太优雅,还可以使用web worker的方式,请求记录会出现在 网络调试工具fetch/xhr里面

Readme

Keywords

none

Package Sidebar

Install

npm i vite-plugin-light-view

Weekly Downloads

0

Version

1.0.6

License

ISC

Unpacked Size

6.38 kB

Total Files

10

Last publish

Collaborators

  • npm262302