Static GitHub Issues

[2960] Are components cached when imported multiple times?

prev: Middleware store dispatch or commit before redirect will not write data on server
next: can't use webpack commonly alias of ~

Hi. I would like to know if when I import the same component in 2 different pages, will it load 2 times or once?

example: ~/pages/page1:

import SomeComponent from "~/components/SomeComponent.js";

export default {
    components: { SomeComponent }
}

~/pages/page2:

import SomeComponent from "~/components/SomeComponent.js";

export default {
    components: { SomeComponent }
}

When I go from /home (server-loaded) to /page1 (client-loaded, redirected with router), and redirect from /page1 to /page2 (also client-loaded, redirected with router), will the SomeComponent load more than once? Will it need to download the additional bytes?

If yes, then should I put the SomeComponent in ~/plugins/myComponents.js and make it global by doing Vue.use(SomeComponent) there? So that it's loaded only once by client

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2567">#c2567</a>)</em></sub></div>