Static Site Generation (SSG) in Next.js with `getStaticProps`

Xiaoru Li
InstructorXiaoru Li
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Since version 9.3, Next.js added a new life-cycle method getStaticProps for improved Static Site Generation (SSG) support, allowing us to fetch data and create static pages at build time. Together with the new data fetching method getServerSideProps used for Server-Side Rendering (SSR), Next.js allows us to clearly separate code intended for SSG or SSR. This is, in many cases, much better than the classic hybrid approach of getInitialProps.

In this lesson, we will import a JSON file from the file system in the getStaticProps life-cycle method of a Table of Contents page, so that we can render links based on the content we have, and statically generate the page at build time. At the end of this lesson, we will export our app using the next export command to a fully static website.

After this lesson, you will be able to optimize pages that don't need to be updated often on every request by only pre-generating them at build-time, utilizing the new SSG feature.

egghead
egghead
~ 11 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today