I use next js and I’m trying to make a static site with WordPress as a backend, I managed to deploy my site with gitlab which deploys to an ftp server
my problem is that I have to rebuild each time to change the data
I don’t want to use useEffect because it’s not great for SEO
and I can’t use getStaticProps with next js app 14
here is my code
thank you for your help
My code :
async function fetchData() {
const res = await fetch("fetchUrl", {
next: { revalidate: 60 }, // Revalidation ISR (par exemple, toutes les 60 secondes)
});
if (!res.ok) throw new Error("Failed to fetch posts");
return res.json();
}
`export default async function Home() {
const data = await fetchData();
return (
<>
<div className="bg-red-500">data wordpress and deploy ci/cd</div>
<pre>{data.acf.titre}</pre>
</>
);
}
I would like my page to fetch by refreshing the deployed site in the correct way without affecting SEO or performance thanks
2
Answers
From next.js docs:
Incremental Static Regeneration (ISR) enables you to:
Example
Here’s how this example works:
If /blog/26 is requested, Next.js will generated and cached this page on-demand
There might me two possible solutions for your problem:
1- Add a tag in fetch to re-validate path on specific operations ie. when you update your data call that particular tag to revalidate it.
-> fetch(
https://...
, { next: { tags: [‘collection’] } })2- By default NextJs 14 caches your fetch response, so you can make fetch request every time you hit the API. So disable cache by adding this.
->fetch(
https://...
, { cache: ‘force-cache’ | ‘no-store’ })Source – https://nextjs.org/docs/app/api-reference/functions/fetch