frandiox / vite-ssr

Use Vite for server side rendering in Node
MIT License
829 stars 92 forks source link

Is it possible to add ssr support only to some pages? #146

Closed StefanGhiban closed 2 years ago

StefanGhiban commented 2 years ago

I have been wondering if it is possible to configure the plugin in a way that some pages need ssr and some do not. For example, in an app, you might have a presentation part that needs good seo and other pages after a user logs in that do not need.

frandiox commented 2 years ago

You can conditionally pass skip: true in your prod server to skip SSR. It will return an empty index.html that behaves as SPA:

  const { html, headers } = await renderPage(url, {
    manifest,
    preload: true,
    skip: url.includes('/admin/'),
    request,
    response,
  })
StefanGhiban commented 2 years ago

Thanks!