How to staticly generate page on build time (next14/app directory)
Answered
Spectacled Caiman posted this in #help-forum
Spectacled CaimanOP
I want staticly generate page on build time, same as
I've enabled "force-cache" but when I build project and start it I spam refresh in browser and checking CMS usages and still increases how to reslve that issue?
even in page.tsx I have
but still doesnt work what
getStaticProps in page directory I use graphql for that and thats my client variableexport const GraphqlClient = new GraphQLClient("https://graphql.datocms.com", {
headers: {
authorization: env.DATOCMS_API_KEY,
},
cache: "force-cache",
});I've enabled "force-cache" but when I build project and start it I spam refresh in browser and checking CMS usages and still increases how to reslve that issue?
even in page.tsx I have
export const dynamic = "force-static";but still doesnt work what
Answered by B33fb0n3
you can use [generateStaticParams](https://nextjs.org/docs/app/api-reference/functions/generate-static-params) function to generate the site data on build time and after that it should only serve the site data and not fetch again
11 Replies
@Spectacled Caiman I want staticly generate page on build time, same as `getStaticProps` in page directory I use graphql for that and thats my client variable
js
export const GraphqlClient = new GraphQLClient("https://graphql.datocms.com", {
headers: {
authorization: env.DATOCMS_API_KEY,
},
cache: "force-cache",
});
I've enabled "force-cache" but when I build project and start it I spam refresh in browser and checking CMS usages and still increases how to reslve that issue?
even in page.tsx I have
js
export const dynamic = "force-static";
but still doesnt work what
you can use [generateStaticParams](https://nextjs.org/docs/app/api-reference/functions/generate-static-params) function to generate the site data on build time and after that it should only serve the site data and not fetch again
Answer
will still resolve my issue?
im directly fetching in
page.tsx@B33fb0n3 you can still use it, to make sure to use ISR:
Spectacled CaimanOP
oh okay got it
@Spectacled Caiman oh okay got it
when will you test it, if this resolves your issue?
@B33fb0n3 when will you test it, if this resolves your issue?
Spectacled CaimanOP
not today 😭
cant
but im pretty sure it resolves the issue because i had already in layout and couldnt receive session because of staticly generated
ah ok, happy to help 👍