Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Next.js Tutorial
  • Next.js Components
  • Next.js Functions
  • Next.js Deployment
  • Next.js Projects
  • Next.js Routing
  • Next.js Styles
  • Next.js Server-Side Rendering
  • Next.js Environment Variables
  • Next.js Middleware
  • Next.js Typescript
  • Next.js Image Optimization
  • Next.js Data Fetching
Open In App
Next Article:
Different forms of Pre-rendering in NextJS
Next article icon

Different forms of Pre-rendering in NextJS

Last Updated : 22 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Next JS is a React-based full-stack framework that enables functionalities like pre-rendering of web pages. Unlike traditional react app where the entire app is loaded on the client, Next JS allows the web page to be rendered on the server, which is great for performance and SEO. You can learn more about Next Js here.

Next.js supports two main forms of pre-rendering: Static Generation and Server-Side Rendering. Both methods generate HTML for pages in advance, but they do so at different times.

Before we get into the different types of Pre-rendering, let's first define Pre-rendering.

Table of Content

  • Pre-rendering in Next.js
  • 1. Static Site Generation (SSG)
  • 2. Incremental Site Regeneration
  • 3. Server-Side Rendering
  • Conclusion

Pre-rendering in Next.js

Next Js pre-renders all pages by default, which means that NextJS will generate HTML for each page in advance rather than relying on client-side javascript to do it all. So, instead of seeing a blank screen and waiting for javascript to load, the user will see complete HTML content on the first load (but with no interactivity until javascript is loaded). The server is responsible for generating all of the content on a web page. Pre-rendering content improves performance and SEO because the SEO crawler can now read actual content quickly and rank your web page accordingly.

with Pre-rendering: 

Without Pre-rendering: 

There are 3 different forms of Prerendering in Next.js

1. Static Site Generation (SSG)

It is the method that generates HTML at build time. The pre-rendered HTML is then used on each request. If we have an HTML page that doesn’t require any external data, Next Js will pre-render its content by default. (Example: About Page). But if our web page requires data from some external API then Next Js, as part of the static generation process will fetch & download the data in advance & generate the HTML. All of this is done during the build time. All of the pre-generated content is then stored in a CDN, so that whenever a user requests to view the web page, a cached version is sent, resulting in improved performance.

This method is suitable for pages with static content, like about page, contact page, etc.

2. Incremental Site Regeneration

In static site generation, there is no room for dynamic content. In this method, HTML is generated at regular intervals, allowing you to create or update static pages after you have built the site. It combines the power of static generation with the flexibility of dynamic content. Whenever a request is made, the page is generated statically with the initialization of a specific interval (say, 60 seconds). After that interval, the page is re-downloaded or re-generated. So the first user may see stale data, but from then on, every user will see fresh data.

This form is suitable for pages that have dynamic content but doesn't change very frequently like the Product page for any e-commerce website as products' price could change.

3. Server-Side Rendering

It is the pre-rendering method that generates an HTML page for each request, making it slower than the other two methods because no content is cached. However, it is appropriate for dynamic content that changes frequently.

This method is suitable for pages like News Feed.

You can now decide which form is appropriate for your web page based on the use case. It's a good practice is to always check to see if we can statically generate any data, as it's much faster. The main advantage of pre-rendering is that SEO crawlers can quickly discover and rank the page content. It also improves performance as the page will render faster because the content has already been rendered.

Conclusion

In summary, Next.js offers powerful and flexible pre-rendering capabilities through Static Generation, Server-Side Rendering, and Incremental Static Regeneration, allowing you to optimize your app for both performance and dynamic content needs.


Next Article
Different forms of Pre-rendering in NextJS

K

ksangtiani13
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • Next.js

Similar Reads

    How to Disable Server Side Rendering on Some Pages in Next.js ?
    In Next.js 13 and above versions you can use the 'use client' directive to disable the server side rendering and enable the client side rendering for some specific pages or components. This directive indicates that the code should be executed on clint side only.Prerequisites :NodejsNext.js, ReactJs
    3 min read
    Next.js Migrating from React Router
    Are you using React Router in your web application and planning to switch to Next.js? Don't worry, the migration process is easy and we've got you covered! This blog post will guide you through the process and help you understand the benefits of doing so. What is Next.js? Next.js is a React-based fr
    5 min read
    How To Fetch Data From APIs In NextJS?
    Fetching data from APIs in Next.js can be done using built-in methods like getServerSideProps, getStaticProps, or client-side fetching with useEffect. This flexibility supports both server-side and static data fetching.Prerequisites:NPM & NodeJSReactJSReact HooksReact RouterApproachTo fetch data
    2 min read
    Next.js Built-in Loader Feature for Smooth Page Transitions
    Next.js offers a built-in loader feature that enhances user experience by providing smooth page transitions. This feature helps to inform users that the application is loading, reducing perceived waiting times and improving overall usability.In this article, we'll explore the Next.js Loader feature
    3 min read
    Server Components in Next.js
    Server Components in Next.js offer a way to build components that are rendered on the server rather than on the client. This feature enhances performance by reducing the amount of JavaScript sent to the browser and allows for faster initial page loads. In this post, we will explore the Server Compon
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences