#Pre-fetching lazy routes

1 messages · Page 1 of 1 (latest)

white grail
#

Hi folks! I'm using RR7 with lazy-loaded routes like

{
  path: "/foo",
  lazy: {
    Component: async () => {
      return (
        await import('./path/to/module')
      ).MyComponent;
    },
  }
}

This works great, but when a user clicks on a link to /foo their browser needs to first load the JS. This can feel a little slow -- is there anything I can do to improve this situation? For example, can I either:

  • show some UI state while fetching the JS, or
  • start pre-loading the JS when the user hovers over the <Link> component?

Thank you!

weary marten
#

You can set loading UI in hydrateFallback or hydrateFallbackElement.