Next.js Series #1-Pages

Search for a command to run...

No comments yet. Be the first to comment.
Bun, the hyper-fast JavaScript runtime known for its incredible speed and Zig-based architecture, is being completely rewritten in Rust. For a project that has over 22 million monthly downloads and ea

Next.js 16.3 is almost here, and it's packed with a ton of improvements and let's see them in this post 1.Instant Navigation For a while now, there’s been a valid, lingering debateServer Components vs

It’s official. React has merged its long-awaited Rust port of the React Compiler (formerly known as React Forget) into the main repository. What started as an experimental research project by Joseph S

If you follow modern technology trends, you have likely been led to believe that artificial intelligence is entirely built on Python. Every tutorial, machine learning framework documentation, and open

Just when the JavaScript ecosystem was catching its breath after last week’s TanStack Router compromise, the Mini Shai-Hulud supply chain worm has continued its relentless march. Developed by the thre

If you don’t have time to read but want to know what’s there in this post. Find the quick read 👇

Intro about Pages
Pages with Dynamic routes
Pre-rendering of Pages
A page in Next.js is similar like a React Component exported from a .js .jsx .ts or .tsx files into the pages directory.Each page is associated with a route based on it’s filename

Example of pages

Next.js supports pages with dynamic routes.

Next.js prerenders everypage in advance instead of having it all done by client-side JavaScript with pre-rendering it will result in better performance and SEO.


If a page uses Static Generation, the page HTML is generated at build time. That means in production, the page HTML is generated when you run **next build**. This HTML will then be reused on each request. It can be cached by a CDN.
In Next.js we can generate pages with and without data like the below scenarios
Static Generation without data
Static Generation with data
Next.js pre-renders pages using Static Generation without fetching data. Here’s an example:

Note that this page does not need to fetch any external data to be pre-rendered. In cases like this, Next.js generates a single HTML file per page during build time.
Some pages require fetching external data for pre-rendering. Your page content depends on external data: **Use getStaticProps**.
If the page paths depend on external data: **Use getStaticPaths** (usually in addition to getStaticProps).

To fetch data on pre-render, Next.js allows you to export an async function called getStaticProps from the same file. This function gets called at build time and lets you pass fetched data to the page's props on pre-render.
Use Static Generation (with and without data) whenever possible because your page can be built once and served by CDN, which makes it much faster than having a server render the page on every request.
You can use Static Generation for many types of pages like below

On the other hand, Static Generation is not a good idea if you cannot pre-render a page ahead of a user’s request. Maybe your page shows frequently updated data, and the page content changes on every request.
If a page uses Server-side Rendering, the page HTML is generated on each request.To use Server-side Rendering for a page, you need to export an async function called getServerSideProps. This function will be called by the server on every request.
For example, suppose that your page needs to pre-render frequently updated data (fetched from an external API). You can write getServerSideProps which fetches this data and passes it to like below

As you can see, getServerSideProps is similar to getStaticProps, but the difference is that **getServerSideProps** is run on every request instead of on build time.
