1

Recently I created an admin panel using vue and laravel.

All things working correctly but one problem is that my compiled script file is almost 7mb file (i.e app.js which is located in public folder) because of this compiled script browser take to long loading time to load initial (landing page) on browser i.e it does not render page until 7mb script get downloaded in browser which is almost 1 min.

Is it possible to load initially one component at start after that according to user click load other component.

In more detail: suppose my app.js file has 1K lines of code and at start if few lines of code get downloaded

then it renders page i.e it should not wait to download complete 7mb script after that it render page.

Is there anyway to reduce this loading time . I did lots of google but haven't find any solution

2
  • 1
    You may want to look into code splitting: 3 Code Splitting Patterns For VueJS and Webpack Commented Feb 17, 2018 at 11:53
  • @yuriy636 its throw error Unexpected token when i use this const Full = () => import('./containers/Full') Commented Feb 17, 2018 at 12:11

1 Answer 1

4

Try to use es6 dynamic import. This entry in vue document and link in vue-router may help you

In addition, 7 mb of pure JavaScript code, on my perspective, is a very complicated spa. Are you sure you minify your code and avoid bundling something like big images?

Now that you use vue-router, I suggest that you use the method described in the vue-router document, as it's based on vue component's async loading and webpack's code splitting feature.

Remember to import syntax-dynamic-import plugin to avoid the unexpected token error you mentioned above. mentioned in vue-router document

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

1 Comment

i go throw all document which you had describe so which one should i use i my application have have router. so should i use Lazy Loading Routes or component or both ?

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.