#What decides SSG?

22 messages · Page 1 of 1 (latest)

warm bramble
#

Hey there, so in a chapter "Implement SSG" in an online Next.js course, the instructor says that by adding "cache: force-cache" within the fetch function, we can implement basically cause Static Site Generation. Is that true though? I dont know... online, I came across other resources which say that this has nothing to do with the SSG itself. SSG will be caused by using "getStaticProps", not by using any caching options. The caching action is only there to fetch data from the cache (if available)...

Yet, the instructor did NOT use getStaticProps, and during the build, Next.js used SSG for that site. Im pretty confused at this point.

Please let me know if I understood these things wrong.

quaint smeltBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

chrome patrol
#

in the app router, you can use export const dynamic = 'force-static'

#

"cache: force-cache" is just an option for the fetch function

warm bramble
#

I see, thank you for that! The instructor used the pages router and Next.js 14. She did not use any of the 2 options, only "cache: force-cache" and the pages were converted to SSG when using the build command.

Now what if you dont provide anything on page - will it by default become SSG?

chrome patrol
warm bramble
chrome patrol
#

so to summarize, to ensure your page is static, rather than using cache: force-cache I would recommend using export const dynamic = 'force-static'

warm bramble
chrome patrol
#

by default it's no-store

#

not static by default, that's why you added "force-cache", right?

warm bramble
# chrome patrol not static by default, that's why you added "force-cache", right?

You are right, my bad. I think my problem of understanding is the following:
I personally understand the concepts of SSG, ISR and SSR pretty well, I'd say.

My problem is - I can't really wrap my head around WHEN and through what actions on my (the developer's behalf) next.js creates a page via SSG / ISR / SSR. Like, I don't understand what that depends on, and what actions in my code cause a page to be created via SSG, ISR or SSR. I worked with Next.js 14 the last time, so maybe some things I assume are a little outdated

#

Does it only depend on my cache settings within a fetch function? What if there is no fetch function? These things are cooking me. Other than that, I understand the concepts of the different rendering approaches

chrome patrol
#

your page becomes dynamic

chrome patrol
#

if you build your project, you have the output in your terminal and you have very good build map (sorry for the bad word but) that helps you to understand what pages are dynamic/static/ISR ...

chrome patrol
warm bramble
# chrome patrol yr welcome! please mark solution to close this thread if you don't have any othe...

Just to wrap this up so I wont have to ask again (correct me if Im wrong):

  1. If I want ISR in Next.js 15, I only export this at the top of my component:
    export const revalidate = 10;

  2. If I want SSG in Next.js 15, I only export this at the top of my component:
    export const dynamic = 'force-static';

  3. If I dont specify anything and do not fetch anything, it will be a SSG by default.

  4. If I fetch data and dont specify anything, it will be SSR by default.