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

Link Prefetching: also prefetch pageContext #246

Open
XiNiHa opened this issue Jan 19, 2022 · 12 comments · May be fixed by #1617
Open

Link Prefetching: also prefetch pageContext #246

XiNiHa opened this issue Jan 19, 2022 · 12 comments · May be fixed by #1617

Comments

@XiNiHa
Copy link
Contributor

XiNiHa commented Jan 19, 2022

Currently, there's no way to do any user-defined additional preloading jobs after finishing to preload static assets. So it's impossible to prefetch data needed for routes. Having an onAfterPreload hook (tried to match the naming convention) will solve the problem and it'll be very helpful to deeply tune the page performance.

@brillout
Copy link
Member

brillout commented Jan 19, 2022

My idea so far for this is to:

  1. Extend the prefetchLink option, e.g.:
    useClientRouter({
      prefetchLinks: {
        prefetchPageContext: {
          when: 'HOVER',
          expire: 5 * 1000 // The prefetched `pageContext` is considered fersh for 5 seconds
        },
        prefetchSaticAssets: {
          when: 'VIEWPORT'
        }
      }
    })
  2. Allow the definition of a client-side-only onBeforeRender() (needed for tools such as Relay).

@brillout brillout changed the title Provide onAfterPreload hook for client router Link Prefetching: also prefetch pageContext Jan 19, 2022
@XiNiHa
Copy link
Contributor Author

XiNiHa commented Jan 19, 2022

I agree with you, that sounds very simple and straightforward.

@brillout brillout added the enhancement ✨ New feature or request label Jan 19, 2022
@brillout
Copy link
Member

brillout commented Jul 10, 2022

With 0.4 the DX is quite straightforward:

// /renderer/_default.page.client.js

export const prefetchStaticAssets = { when: 'VIEWPORT' }
export const prefetchPageContext = { when: 'HOVER', expire: 10 * 1000  }

Implementation should be fairly easy.

@archit-p
Copy link

archit-p commented Apr 3, 2023

Hi @brillout, is this part of the v1 design (#578) and being worked on? I'd love to work on it!

@brillout
Copy link
Member

brillout commented Apr 3, 2023

@archit-p It isn't but this feature can be implemented independently of the V1 design. PR welcome!

@usk94
Copy link
Member

usk94 commented Apr 21, 2024

Hi, @brillout!
May I work on it?

@brillout
Copy link
Member

Hi @usk94, yes!

@usk94 usk94 linked a pull request Apr 22, 2024 that will close this issue
@usk94
Copy link
Member

usk94 commented Apr 22, 2024

@brillout
Let me ask a question.
Should prefetchPageContext.when default to false?
Also, do I need to support override for individual links?

@brillout
Copy link
Member

So far I'm inclined to think that we can enable it on HOVER by default. But let's see.

Also, do I need to support override for individual links?

I think that would be nice? Or do you see an issue with that?

@usk94
Copy link
Member

usk94 commented Apr 23, 2024

@brillout
OK, I'll implement HOVER as default for now🙆‍♂️

Or do you see an issue with that?

I don't have at the moment. I just asked to be sure, thank you!

@loteoo
Copy link
Sponsor

loteoo commented May 2, 2024

Just sharing my interest in this issue :)

Two considerations:

  • Is there a way to reuse some of the logic that is already in place for the loading of the page JS bundles?
  • Would it make sense that, for static sites, it would only fetch the page context once per page? (keeps the data in memory, doesn't re-fetch it if it already has it?)

Loving vike for static sites! ❤️

@brillout
Copy link
Member

brillout commented May 3, 2024

I'm not sure I understand your first point. The second point makes a lot of sense, although it isn't the focus right now to make it perfect (the sponsor who requested this feature doesn't use SSG). Let's see.

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

Successfully merging a pull request may close this issue.

5 participants