Skip to main content

Posts

Showing posts from March, 2025

Understanding SSR, SSG, and ISR in Next.js: Pages Router vs. App Router

Next.js Pages Router vs App Router Next.js Pages Router vs App Router Next.js provides two routing and data-fetching strategies: Pages Router (pages/) and App Router (app/). Each has its own way of handling Server-Side Rendering (SSR), Static Site Generation (SSG), and Incremental Static Regeneration (ISR). Comparison Table Feature Pages Router (pages/) App Router (app/) SSR (Server-Side Rendering) getServerSideProps fetch() with cache: "no-store" SSG (Static Site Generation) getStaticProps fetch() with cache: "force-cache" ISR (Incremental Static Regeneration) getStaticProps + revalidate: X fetch() with { next: { revalidate: X } } Client-Side Rendering (CSR) ...

Next.js Data Fetching Explained: CSR, SSR, SSG, ISR with Axios & WebSockets

Understanding Data Fetching in Next.js: CSR, SSR, SSG, and ISR with Axios & WebSockets Next.js provides multiple ways to fetch data from an API: CSR (Client-Side Rendering), SSR (Server-Side Rendering), SSG (Static Site Generation), and ISR (Incremental Static Regeneration). Each method serves a different purpose, affecting performance, SEO, and user experience. In this guide, we will explore how to use Axios for API requests and integrate WebSockets for real-time updates. 🔹 1. CSR (Client-Side Rendering) - Fetch Data with Axios CSR means fetching data on the client side, after the component mounts. The data is NOT available during the initial page load. ✅ When to Use CSR? For real-time updates (e.g., chat apps, stock prices). When SEO is not a priority (search engines see an empty page first). For highly interactive applications . 📌 Example: Fetching Data with Axios in CSR import { useEffect, useState } from 'react'; import axios fro...