Search code examples
next.jsstaticserver-side-rendering

Nextjs - if i dont use getServerSideProps or getStaticProps are my static pages then served optimised?


Speaking about Next.js v12 Should i render completely static pages like contact page or policy pages with empty getStaticProps exports or without anything to serve them with results created during build time?


Solution

  • If your page content is entirely static and doesn't require any data fetching or pre-processing, you can omit the getStaticProps function altogether. Next.js will automatically treat the page as static during the build process. when you build your page, your dynamic pages will be marked with lambda sign and static pages as round sign

    getStaticProps is used for pre-rendering pages with Static Generation (SSG). It allows you to fetch data at build time and pass it as props to your page components. for example if you have 10 blog posts in your database, during build time it will fetch all the blog ids and generate html for each blog and cache it.