Nuxt generate server bundle (pre-rendered HTML + SSR combo)

MarvinMiles
25
MarvinMiles
commented 6 months ago

What problem does this feature solve?

Point is to combine pre-rendered HTML with SSR functionality (to handle dynamic routes from server, for example) within one "generate+build" process.

Using "nuxt generate" for static hosting and "nuxt build" for server - doesn't work. Two webpack bundles causing losing hydration - some js files get 404 error (different hashes, paths).

What does the proposed changes look like?

Nuxt already offers cool feature "generate.fallback" to combine pre-rendered + SPA functionality.

Would be nice to have something like "generate.ssr = true" for pre-rendered + SSR functionality.

idea
0
Timkor
6
Timkor
commented 5 months ago

It would nice if Nuxt could cache pages based on some properties. That way we could implement the caching ourselves if necessary.

0
kalenjordan
0
kalenjordan
commented 5 months ago

I think this is also something that I need. The initial server response time is regularly >1.5s which is quite slow IMO. Getting that initial page to load static index.html with a fallback for dynamic routes would be awesome.

0
pimlie
928
pimlie
commented 5 months ago

@Timkor, are you aware of the possibility of component caching? https://nuxtjs.org/faq/cached-components#how-to-cache-vue-components-

0
trylovetom
0
trylovetom
commented 16 days ago

My Solution

  • nuxt.config.js
export default {
  mode: 'universal',
  serverMiddleware: [
    '@/serverMiddleware/selectNuxtMode'
  ]
}
  • /serverMiddleware/selectNuxtMode.js
export default function selectNuxtMode (req, res, next) {
  const isNotCrawler = !req.isCrawler
  res.spa = isNotCrawler
  res.setHeader('mode', res.spa ? 'spa' : 'universal')
  return next()
}

Or you can use reverse-proxy such like Nginx, HAProxy

0
Informations
Feature Request โ€ข Open
#c8583 - Created 6 months ago