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

Prefetch page content via Ajax on link hover #6241

Open
connecteev opened this issue Aug 18, 2019 · 9 comments
Open

Prefetch page content via Ajax on link hover #6241

connecteev opened this issue Aug 18, 2019 · 9 comments

Comments

@connecteev
Copy link

What problem does this feature solve?

Instantclick (http://instantclick.io) is a nifty little js library (< 3kb gzipped) that pre-fetches pages via Ajax when you hover on links, based on the user's intent to click on it. A great example of a site that does that is dev.to (example: go to https://dev.to/t/vue, open up the console and notice the ajax requests when you hover on any link)
Does Nuxt support this natively? I see some mentions of "prefetching" in the API documentation but I don't see it happening on my nuxt instance (I am on nuxt-edge). Is this functionality available in Nuxt?
https://nuxtjs.org/api/configuration-router#prefetchlinks

Is it off by default, perhaps? If it's not available, this would be a really nifty thing to add to the core library, perhaps as a configuration option.
It would also be helpful to get more information on what "prefetch" in the API documentation is referring to, and how one can see it in action.

This feature request is available on Nuxt community (#c9652)
@ghost ghost added the cmty:feature-request label Aug 18, 2019
@manniL
Copy link
Member

manniL commented Aug 18, 2019

Hey 👋
Nuxt is prefetching the JS chunks corresponding to the page by default (when a link is in the viewport and the user has a good connection). it does not execute asyncData or fetch of that page.

Executing these functions beforehand might lead to inconsistencies of the app state (especially when the content in the store will change before the page is even visible).

I agree, the docs need a chapter about the current behavior.

More info in #4574

@connecteev
Copy link
Author

Thanks for the links @manniL. So there are 2 threads here:

  1. Re: understanding current functionality: I agree, the nuxt documentation assumes a lot and has no real examples....I still struggle with it every day. I hope that changes in 3.x to make the framework more approachable to "non power developers"
    So Nuxt prefetches chunks of js for every link that is in the viewport, and this is by default, is that correct? Looking at this hello world example
    One thing I don't understand, why are scripts like /_nuxt/runtime.js and /_nuxt/vendors.app.js both preloaded and "deferred" on the same page?

  2. I believe it still makes sense to keep this feature request open, and provide an option in Nuxt to turn on asyncData or fetch of the entire page, on certain actions like hover / hover with delay like www.instantclick.io does it? Would you agree?

Thanks..

@manniL
Copy link
Member

manniL commented Aug 18, 2019

So Nuxt prefetches chunks of js for every link that is in the viewport, and this is by default, is that correct?

Yes but only if the connection is good (better than 2G) and no data saver is enabled. Also, the browser has to support IntersectionObserver.

I hope that changes in 3.x to make the framework more approachable to "non power developers"

What could we do to improve the docs in your opinion?

re 2: We can keep it open, sure.

@connecteev
Copy link
Author

connecteev commented Aug 18, 2019

@manniL
Re: improving the docs, I'll add a separate enhancement for that so as not to muddy this one

@tr1s
Copy link

tr1s commented Mar 28, 2020

Coming from Gatsby, I decided to make a project in Nuxt, and was suprised to see all the components pre-fetched! I like the concept of only prefetching on hover and it would be a nice feature to have in Nuxt!

@manniL
Copy link
Member

manniL commented Mar 31, 2020

Coming from Gatsby, I decided to make a project in Nuxt, and was suprised to see all the components pre-fetched! I like the concept of only prefetching on hover and it would be a nice feature to have in Nuxt!

At the moment, prefetching works via intersection observer (when a <nuxt-link> is in the viewport).
But that's not related to the actual issue here 🙈

@simplenotezy
Copy link

This would be a cool feature!

@kirtan403
Copy link

Any update about the progress here?

@fahmifitu
Copy link
Contributor

This is still a nice feature to have in 2022

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

No branches or pull requests

7 participants