vuejs / vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
http://v2.vuejs.org
MIT License
207.85k stars 33.68k forks source link

shouldPrefetch enhancement #7139

Open FranckFreiburger opened 6 years ago

FranckFreiburger commented 6 years ago

What problem does this feature solve?

Currently, I use import(/* webpackChunkName: "lang-[request]" */ json!yaml!./myForm.lang.${currentLocale}.yaml) to load the appropriate translation for my components.

This generates numberOfForms * numberOfLangages chunks that are prefetched when the application starts.

I would like to load only translations for the current language.

shouldPrefetch(file, type) gives

0.js script
1.js script
2.js script
...

There is not enough information to filter files that should not been prefetched.

What does the proposed API look like?

I don't know what are the available information at shouldPrefetch. But probably API should look like: shouldPrefetch(file, type, originalFilename)

posva commented 6 years ago

FYI shouldPreload has the same parameters as shouldPrefetch : https://ssr.vuejs.org/en/api.html#shouldpreload

FranckFreiburger commented 6 years ago

I also need to prefetch only files related to the current user's langage. User's langage is stored (server-side) in the application i18n.locale. shouldPrefetch() should also expose the application that is currently server-side rendering (or at least its context).

FranckFreiburger commented 6 years ago

ping !

wxsms commented 4 years ago

Agree. file param of shouldPrefetch and shouldPreload are too hard to use.

I'm a user of vuepress, it make's me very difficult to decide which pages to prefetch while number of pages growing fast. Although with this option provided, but it's just like a simple boolean value: 'prefetch everything' or 'prefetch nothing'.

Hopefuly there will be any enhencements. Thanks!