⚠️
The vite-plugin-ssr project has been renamed Vike.
  • If you are using vite-plugin-ssr, migrate to Vike.
  • For new projects, use Vike instead of vite-plugin-ssr.
Vike itself (without extensions) is like vite-plugin-ssr: unopinionated and fully agnostic.

prefetch()

Environment: browser.

We can use prefetch('/some/url') to programmatically prefetch pages.

⚠️
prefetch() works only with Client Routing. Prefetching isn't possible with Server Routing.

We usually use prefetch() to speed up page navigation when we can predict what the next page will (most likely) be.

For example:

import { prefetch } from 'vite-plugin-ssr/client/router'

function Form() {
   return (
     <form onSubmit={onSubmit}>
       {/* ... */}
     </form>
   )
}

async function onSubmit() {
  // We fetch the next page
  prefetch('/form/success')
  // In parallel we make a request to our server
  await someRequestToServer()
  // The assets of the next page may already be fetched at
  // this point, before even calling navigate()
  await navigate('/form/success')
}