Next.js Discord

Discord Forum

is moving user-id to url better for caching?

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
It is a common pattern to fetch data for user in a web application. What I usually do is for a page /page_1, I make it an async server component, read the session data and fetch data from database. However, I realised, nextjs might not be caching the html because the url is not unique for each user.

So, I am wondering if I should move the user-id to url and use a middleware to change the url from /page_1 to /user_id/page_1 then the url of each page would be unique and nextjs can cache the html. I understand that I now have to manually invalidate the caches (and the url becomes kinda ugly) and thats okay. But I am wondering if there is any other catch?

Your opinion would be very helpful. thanks

0 Replies