jpkleemans / vite-svg-loader

Vite plugin to load SVG files as Vue components
MIT License
554 stars 58 forks source link

请问,是否支持打包合并为一个文件的功能(Excuse me, does it support the function of packaging and merging into one file) #102

Closed WangJincheng4869 closed 7 months ago

WangJincheng4869 commented 1 year ago

目前打包后每个SVG会是一个js文件,这样会出现很多几百字节的文件,小文件过多会影响请求性能,如果将其合并为一个文件,这样对服务器的压力会降低。 At present, after packaging, each SVG will be a JavaScript file, which will result in many hundreds of bytes of files. Excessive small files will affect request performance. If they are merged into one file, it will reduce the pressure on the server. image

StereoApp commented 11 months ago

我理解这样才能实现按需加载,一个页面不会有太多的图标,除非是图标选择器的场景,如果都打成一个的话,每个用图标的地方都要加载一个大文件,如果系统图标特别多的话会影响首屏加载速度。

WangJincheng4869 commented 11 months ago

我理解这样才能实现按需加载,一个页面不会有太多的图标,除非是图标选择器的场景,如果都打成一个的话,每个用图标的地方都要加载一个大文件,如果系统图标特别多的话会影响首屏加载速度。

但其实过多小小请求更会影响性能,毕竟每个请求都是一次完整的请求,都得从 tcp 连接开始到 tcp 连接断开。 就算一个网站用了 1000 个图标,多算点每个图标 1kb,那才1M(未压缩的情况)

所有我觉得这个可以作为配置项,自己可以选择打包为一个js还是分开打包。我想超过99%的项目图标都不会超过一千个....

But in fact, having too many small requests can even affect performance, as each request is a complete request that must start from the TCP connection until the TCP connection is disconnected. Even if a website uses 1000 icons and calculates an additional 1kb for each icon, that's only 1M (uncompressed)

I think this can be used as a configuration item, and I can choose whether to package it as a single JavaScript or separately. I don't think over 99% of project icons will exceed a thousand