nitro icon indicating copy to clipboard operation
nitro copied to clipboard

allow excluding routes from prerenderer crawling

Open danielroe opened this issue 2 years ago • 5 comments

Would be nice if something is intended to be dynamic.

Perhaps we could support prerender.exclude with RegExp, function or string signature? Or a render hook with option to skip rendering (https://github.com/unjs/nitro/issues/88)?

danielroe avatar Jun 22 '22 13:06 danielroe

@pi0 What are your thoughts regarding implementation ? Let me know if I can help :)

kevinmarrec avatar Jun 28 '22 16:06 kevinmarrec

Sure makes sense to introduce an option (array) filtering exact URLs for patterns with * and **. (I would avoid less explicit fn and regex and hook allows to have advanced context).


(off topic) BTW I can see this is linked to https://github.com/kevinmarrec/nuxt-pwa-module/issues/7. The module should probably use a server handler to generate manifest which then works with nitro :) We can also improve the crawler to avoid overriding already written (public) assets. I wouldn't use feature from this issue for working around.

pi0 avatar Jun 29 '22 09:06 pi0

One thing I do like about the Next implementation is that you can specify on the page component whether it should be prerendered or not. Did you consider something like this on the template or script tag? eg:

<template static>
</template>

This would prevent complex rules that people would have to learn. Maybe even make it work so it applies the setting to any nested pages (for example on a blog page and that all of its article detail pages automatically would have static generation applied)

chris-visser avatar Jun 30 '22 19:06 chris-visser

@chris-visser This is possible to be done using unified route rules to specify group of routes to be static cached (prerenderd)

https://github.com/nuxt/framework/discussions/560

pi0 avatar Jul 01 '22 09:07 pi0

Wauw nice! Have a lot of catching up to do with all of Nuxt 3's features, but honestly great stuff!

chris-visser avatar Jul 01 '22 09:07 chris-visser

Seems like simple string filtering is supported with commit https://github.com/unjs/nitro/commit/a6cbbbe482243a3d8dc4c3917ec406b74fdb2a8f and the prerender.ignore option. It just seems to be undocumented right now.

hanneskuettner avatar Mar 07 '23 11:03 hanneskuettner

I now have a need to exclude all routes except several routes to be prerendered. But plain string prefix won't work for me, neither will routeRules work (which will cause the index page to be prerendered when in SSR mode). I've already made a PR for that.

thezzisu avatar Mar 07 '23 13:03 thezzisu

Just started testing pre-rendering and route rules but they do not feel intuitive to me, especially when crawling is on it means I have to duplicate route logic. Thoughts on using routeRules for matching routes to prerender instead of having a separate ignore option?

E.g. to prerender articles: routeRules: { '/articles/**': { static: true } }

Siilwyn avatar May 17 '23 14:05 Siilwyn

I believe this is possible with routeRules and prerender:false : routeRules: { '/articles/**': { prerender: false } }

Hebilicious avatar Jul 28 '23 13:07 Hebilicious

  • We have predenrer:routes in order to extend via hook

pi0 avatar Jul 28 '23 15:07 pi0