-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Martina Bustacchini <martina.bustacchini@redturtle.it> Co-authored-by: Mauro Amico <mauro.amico@gmail.com> Co-authored-by: Steve Piercy <web@stevepiercy.com> Co-authored-by: Víctor Fernández de Alba <sneridagh@gmail.com>
- Loading branch information
1 parent
1596de2
commit 6f18663
Showing
182 changed files
with
1,898 additions
and
1,830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
myst: | ||
html_meta: | ||
"description": "Bundle size optimization in Volto" | ||
"property=og:description": "Bundle size optimization in Volto" | ||
"property=og:title": "Bundle size optimization" | ||
"keywords": "Volto, Plone, frontend, React, Performance, guidelines" | ||
--- | ||
|
||
(bundle-size-optimization-label)= | ||
|
||
# Bundle size optimization | ||
|
||
This document describes how to optimize the bundle size of components through {term}`lazy loading` to improve page load times. | ||
Contributors to Volto core should follow the guidelines in this document. | ||
|
||
|
||
## Lazy loading in core | ||
|
||
Since Volto 18, several core components use lazy loading to keep the final build size under control. | ||
|
||
For example, the `Form` components are lazy loaded, which means that the code for the form components is only loaded when the user navigates to a page that contains a form. | ||
A new index file has been created at `packages/volto/src/components/manage/Form/index.tsx` that exports the form components with lazy loading. | ||
The `export`s in the main components index (`packages/volto/src/components/index.js`) have been updated to export components from the new specific index. | ||
The same goes for other components that have been lazy loaded, such as the control panels and widgets. | ||
|
||
Several `import` statements have been updated to use the new lazy loaded components. | ||
For example, the `Form` component is now imported from `@plone/volto/components/manage/Form` instead of `@plone/volto/components/manage/Form/Form`. | ||
You should keep this in mind, and always import components from the specific component index files when available, while avoiding importing components from the main components index file, if possible. | ||
This should also help to reduce circular dependencies, and help the overall build performance in the long run. | ||
|
||
|
||
### Unit test components that use lazy loaded components | ||
|
||
If you import a component from a lazy loaded index, you can have issues with rendering these in unit tests. | ||
Mocks are provided for lazy loaded components and are available for you to use. | ||
This can be done by using the `jest.mock` function to mock the specific component index. | ||
For example, to mock the `Form` component and all other components in the `Form`-specific index, you can use the following code in your test file: | ||
|
||
```javascript | ||
jest.mock('@plone/volto/components/manage/Form'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update imports to work with the new code split components in Volto. @pnicolli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reduced JavaScript bundle size of the production build. Code split several internal modules: Controlpanels, Form, Widgets among other small ones. @pnicolli @deodorhunter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.