Next.js Discord

Discord Forum

Caching or something else

Unanswered
Florida White posted this in #help-forum
Open in Discord
Florida WhiteOP
NextJS 15.5.3
Application deployed to server based on windows server and output 'standalone'
Issue: On production server, when I hit a first url, the data loads around 1 second - I'm fetching few dictionaries + search data. Everything is client-side and I'm fetching via SWR -> Route Handler -> External .NET API. Question is what can be wrong?

Components Flow
1. Page.tsx - useState just for handling my state for rendering modal
2. Table Componenent inside Page.tsx - here I use my custom hook for setting params, I have some default params for search so I check for it and if they are not in url I'm pushing it to router.
For example - User opens my-page.com and then go to my-page.com/vehicles, I'm doing my-page.com/vehicles?page=1&itemsPerPage=10. Then there are fetches for dictionaries and based on searchParams i'm fetching Vehicles itself to grid. All requests in screenshots seems to work in parallel so it's not like 5 seconds wait but 1 -2 seconds generally.

In the screenshots, after first load I can refresh page using ctrl+r every second and it's fine, always miliseconds. But when I wait 10 seconds and hit refresh then it's taking again more time. Funny thing is that if DB is refreshed, I'm getting no results so it should be extra fast like - fetching nothing

Cache?
External API issue?

I hope you will know 😄

12 Replies

Rex
Idk if this is relevant to your issue, but i am also having what appears to eb a caching issue where if i load in on like site.com/dashboard via ssr, and then if my other pages are prefetched, whenever i route to other pages such as site.com/account, etc it loads instantly due to prefetching, but whenever i try to route back to eth orignal url i loaded in on, (such as site.com/dashboard in this example) then that route is never cached and I always have to wait like the second or so for it to refetch.

and this is happening for all cases for whatever the first page was that i loaded in on.

Is this something your encountering here too? Or along similar lines?

I DONT have an answer for it yet but jsut thought id drop it here
Florida WhiteOP
BUMP
Florida WhiteOP
BUMP
it seems that the issue is with Route Handler

I tried to request it without the UI and it seems that when I try to hit the endpoint in max 5 seconds it's cached or something and taking miliseconds. After it again it takes 1-2 seconds which is pretty interesting because in my testing case I should receive empty array so actually no results - extra small
Florida WhiteOP
Maybe the problem here is an middleware or something? My route is pretty simple

fetch from external api in try/catch and that's all
Check this ticket i opened regarding my issue. Response says that is in intended behavior and to cache the function
Florida WhiteOP
Yeah but I'm using route handler /api + SWR to fetch it on client
I spent like two days for search and it seems that something is wrong somewhere else - time for server response - this is the crutial thing which is causing like 1s delay
Florida WhiteOP
BUMP