Static page with search params
Unanswered
Amur catfish posted this in #help-forum
Amur catfishOP
Is there a way to have a page that is statically generated, and when you add search params to it, it will fallback and render dynamically?
For example if you have a blog at
This doesn't seem possible with next right now without doing weird middleware stuff. Is there any tehnical reason for that, or am I missing something? I feel like it should just be able to treat it as a normal param...
For example if you have a blog at
/blog with static content, and you want some filtering, /blog?q=test should be a dynamic page, where it searches the blog for test.This doesn't seem possible with next right now without doing weird middleware stuff. Is there any tehnical reason for that, or am I missing something? I feel like it should just be able to treat it as a normal param...
5 Replies
@Amur catfish Is there a way to have a page that is statically generated, and when you add search params to it, it will fallback and render dynamically?
For example if you have a blog at `/blog` with static content, and you want some filtering, `/blog?q=test` should be a dynamic page, where it searches the blog for `test`.
This doesn't seem possible with next right now without doing weird middleware stuff. Is there any tehnical reason for that, or am I missing something? I feel like it should just be able to treat it as a normal param...
the problem is that in nextjs, a page.js can only be either static or dynamic. you can't change the staticity depending on the incoming request.
i'd cache the page data for
i'd cache the page data for
/blog (with fetch or unstable_cache), then use that cached page data if there is no search params. in that way, while /blog is still dynamic, the most expensive part of it (the data) is static, so it's still performant.@joulev the problem is that in nextjs, a page.js can only be either static or dynamic. you can't change the staticity depending on the incoming request.
i'd cache the page data for `/blog` (with `fetch` or `unstable_cache`), then use that cached page data if there is no search params. in that way, while `/blog` is still dynamic, the most expensive part of it (the data) is static, so it's still performant.
Amur catfishOP
I feel like you sort of do this if you statically generate a page, but keep fallback to "blocking". In that case it would be dynamic, waiting for it to fetch the data, if the page wasn't statically generated, right?
So I feel like that should technically be possible with search params too, just that it isnt..
i fully agree
but yeah unfortunately this is what we are stuck with