Next.js Discord

Discord Forum

Unexpected caching behaviour for page.tsx files

Unanswered
Ben Jackson posted this in #help-forum
Open in Discord
Can you help me understand what is happening here:

I have 3 page routes. Each of them have links to the other pages and they also have a console.log('Page 1') in the page render function body. If I click between the pages the first time each page is rendered, the log is output to the server console as expected.

On subsequent visits the logs are not rendered which I assume is because of some browser caching.

However: if I then wait around 1 minute or so, after that point each log occurs every time I visit each page. i.e. there doesn't appear to be any caching after this point.

I can't work out why this is. What's going on here? Does this ring any bells?

1 Reply

I've found what the behaviour I was observing is. It's Next's Router Cache which happens in the browser. https://nextjs.org/docs/app/building-your-application/caching#4-nextjs-caching-on-the-client-router-cache