英文:
Omit theme loading of unused components and avoid network load in Vaadin 23
问题
我刚刚意识到我的Vaadin Web应用程序在总共8MB的JavaScript网络加载印记中至少加载了3MB的未使用的JS主题库。如何防止这种情况发生?
最突出的三个是:
- 1600kb的Vaadin图表
@vaadin_charts_theme_lumo_vaadin-chart__js.js
- 大于340kb的Vaadin地图
@vaadin_map_theme_lumo_vaadin-map__js.js
- 大于310kb的Vaadin富文本编辑器
@vaadin_rich-text-editor_theme_lumo_vaadin-rich-text-editor__js.js
是否可以通过Vite的某种方式来排除它们?
Vaadin版本:23.3.4
(非生产模式)
我没有使用任何商业组件,并已尝试在pom.xml中明确排除它们,还从package.json中删除它们,然后重新运行了npm i
。
英文:
I just realized that my Vaadin Web Application loads at least 3mb of unused JS theme libraries out of an 8Mb overall javascript network loading footprint.
How can this be prevented?
The three most prominent
- 1600kb vaadin charts
@vaadin_charts_theme_lumo_vaadin-chart__js.js
- >340kb vaadin map
@vaadin_map_theme_lumo_vaadin-map__js.js
- >310kb vaadin rich text editor
@vaadin_rich-text-editor_theme_lumo_vaadin-rich-text-editor__js.js
Can this be excluded with Vite somehow?
Vaadin version: 23.3.4
(non-production mode)
I am not using any of the commercial components and have tried to explicitly exclude them from the pom.xml and also removed them from package.json, then started npm i
again
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin</artifactId>
<exclusions>
<exclusion>
<groupId>com.vaadin.addon</groupId>
<artifactId>vaadin-charts</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-rich-text-editor-flow</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-map-flow</artifactId>
</exclusion>
<!-- [..] -->
答案1
得分: 7
在开发模式下,会加载许多额外的JS。应该在生产模式下运行测试,在此模式下,会扫描实际使用的组件,并创建一个优化的JS捆绑包。
通常在开发过程中,没有必要阻止从本地主机加载几兆字节的JS。
英文:
In development mode, a lot of extra JS is loaded. You should run your test in production mode where the application is scanned for the components you actually use and an optimized JS bundle is created.
There is usually no need to prevent some MB of JS from being loaded from localhost while developing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论