Joe Seifi
Joe Seifi

Reputation: 1725

Can you opt out of Next.js 14 cache for static sites e.g. output: "export"?

Running next build with output: "export" caches the API calls, meaning any changes do not appear in the resulting static files. Is there any way to disable the caching, or get new data when running the build?

setup:

issue:

Upvotes: 0

Views: 553

Answers (1)

Beast80K
Beast80K

Reputation: 1387

Problem :

Is there any way to disable the caching, or get new data when running the build?

Possible Cause :

  • By default, Next.js automatically caches the returned values of fetch in the Data Cache on the server.

Possible Solution :

Set the cache option for individual fetch requests to 'no-store' :

fetch('https://...', { cache: 'no-store' }) 

Set Route Segment Config Options in your layout.tsx/js or page.tsx/js or route.ts/js (add this line at top of the file) :

export const fetchCache = 'force-no-store'

Please Read :

If you have any doubts, then please leave a comment (I will update answer if necessary)

Upvotes: 0

Related Questions