Next.js Discord

Discord Forum

call api only when refresh the page

Unanswered
Miniature Bull Terrier posted this in #help-forum
Open in Discord
Miniature Bull TerrierOP
Hi, I want to call api only when user first time load the page. after that i want to store it and use it in all pages. can you please help me how to do this

10 Replies

when you start load the page do you mean it will be load in a single particular page or any page ?
Miniature Bull TerrierOP
first time user entered the website or refresh the page
is the API external api or its a nextjs route ?
is the page client side or server-side ?
Miniature Bull TerrierOP
external API
server side
Do you have a snippet that you can share ?
And how often do you want this API to revalidate itself ?
Usually if you use fetch then you can add nextjs exclusive option to revalidate the API. Since it will cache the route by default. But if you want to opt out of it altogether then you can add cache: no-store option to the fetch.