Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Config option to disable prefetch links, or only prefetch certain pages #636

Closed
jakeg opened this issue Jul 6, 2018 · 5 comments

Comments

@jakeg
Copy link

jakeg commented Jul 6, 2018

Feature request

What problem does this feature solve?

Sites with many pages don't want to prefetch all pages. For example, a site with 1,000+ pages may want to prefetch no pages, or a small selection of main pages.

What does the proposed API look like?

In .vuepress/config.js add an option prefetch which defaults to true but can be changed to false to not prefetch any pages, or an array of pages.

module.exports = {
  // To not do any prefetching of pages
  prefetch: false,
  // Or to prefetch a selection of main pages
  prefetch: [
    '/about',
    '/faq',
    '/contact'  
  ]
}

How should this be implemented in your opinion?

Are you willing to work on this yourself?**

@ulivz
Copy link
Member

ulivz commented Jul 7, 2018

For request 1, we have supported, see: shouldPrefetch.

For request 2, Since VuePress's prefetch is based on vue-server-renderer, and only when Vue SSR supports so fine-grained control can we implement it. so please create this feature request for vue-server-renderer.

@ulivz ulivz closed this as completed Jul 7, 2018
@jakeg
Copy link
Author

jakeg commented Jul 9, 2018

Thanks. Really weird caching issue or something on the page you linked to there... at first the shouldPrefetch block didn't appear at all, had to refresh several times to see it.

@ulivz
Copy link
Member

ulivz commented Jul 9, 2018

That's the issue of service worker, make sure you have closed all the previous vuepress website tabs before opening this link.

BTW, we'll have a update popup UI in the future: #533

@rwxrob
Copy link

rwxrob commented Nov 20, 2018

Just a note that the documentation on shouldPrefetch has an example with a preload link in it. It confused me at first having just read about the difference between shouldPreload in the main Vue docs but when I tried both confirmed that shouldPreload is not a VuePress thing and that shouldPrefetch set to false stops all prefetch links in index.html but leaves the essential preload ones.

screen shot 2018-11-20 at 1 11 35 pm

By the way, to anyone coming across this, I have several hundred individual markdown files in my glossary of terms and turning prefetch off dramatically increased load time, obviously. I would look forward to a way to setup some sort of background caching of these resources using the serviceworker instead, but that would be a separate feature request.

@adarshmadrecha
Copy link

Now in v2.5.0 + of vue-server-renderer has support for defining function and can customize which paths should be prefetched.

https://ssr.vuejs.org/api/#shouldprefetch

  shouldPrefetch: (file, type) => {
    // type is inferred based on the file extension.
    // https://fetch.spec.whatwg.org/#concept-request-destination
    if (type === 'script' || type === 'style') {
      return true
    }
    if (type === 'font') {
      // only preload woff2 fonts
      return /\.woff2$/.test(file)
    }
    if (type === 'image') {
      // only preload important images
      return file === 'hero.jpg'
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants