1

I have a vue.js router implemented and if I run npm run build it correctly creates separate files for every component. But if I run npm run serve and then open the page all components files are loaded immediately not lazy. If I click on the link to component it loads the components file again. I don't understand why it is not lazy. Look at the screenshot. There are contact.js (which should be chunk) loaded two times. First on refresh second on link click.

enter image description here

4
  • 1
    it's called prefetching. vue-cli 3 does this by default: cli.vuejs.org/guide/html-and-static-assets.html#prefetch Regarding the chunk being loaded twice, I suggest that you build in production mode and then check the actual response of both the duplicate requests. I think the second time, the chunk only gets loaded from browser cache and does not make a network request Commented Aug 27, 2020 at 7:40
  • Yes it seems like a prefetch. Where I can find something about vue.config.js? Commented Aug 27, 2020 at 7:51
  • 1
    Here: cli.vuejs.org/guide/webpack.html#working-with-webpack Commented Aug 27, 2020 at 7:54
  • 1
    Make an acceptable answer. It works fine with vue.config.js. Everything is ok. Thanks a lot. Commented Aug 27, 2020 at 7:55

1 Answer 1

1

it's called prefetching. vue-cli 3 does this by default as explained here.
Regarding the chunk being loaded twice, I suggest that you build in production mode and then check the actual response of both the duplicate requests. I think the second time, the chunk only gets loaded from browser cache and does not make a network request

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.