You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-3Lines changed: 36 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,39 @@
1
1
# lazydemo
2
+
This is a simple demo showing how to:
3
+
1. Lazy Load Components in Vue 2
4
+
2. Lazy Load Routes in Vue 2
5
+
Bonus: vue.config.js shows how to split out vendor's chunk
6
+
7
+
## Lazy Load Components
8
+
In the /views/home.vue component, Bella is shown by default so we can lazy load the Daisy component since it's not visible on the initial page load.
9
+
10
+
What to Lazy Load? Anything that isn't visible on initial page load. (using v-if)
11
+
- Tabs (other than the default)
12
+
- Side Panel
13
+
- Modals
14
+
15
+
16
+
## Lazy Load Routes
17
+
In the /router/index.js, the About page is already lazy loaded.
18
+
19
+
Typcially, there's not much value in lazy loading the home page, since it is the entry point of the application. If you have multiple entry points, then you may want to lazy load those.
20
+
21
+
To Lazy Load the Bella and Daisy routes, just change the import to a dynamic import. Change this:
22
+
```
23
+
import Bella from '@/components/bella'
24
+
```
25
+
to this:
26
+
```
27
+
const Bella = () => import('@/components/bella')
28
+
```
29
+
30
+
### Specifying Webpack Chunk Name
31
+
1. Babel.config.js must have comments to true for this to work.
32
+
2. Add the webpack magic comment to the dynamic import
0 commit comments