Yogesh Chauhan's Blog

How does Next.js load pages faster?

in NextJS on July 7, 2021

Next.js uses Client-Side Navigation to load the pages faster.

The Client-Side Navigation is enabled by the Link component and only between the pages in the same Next.js app.

So, if you add a link using an a tag then the faster pages switch won’t work!

What’s a Client-side navigation?

Client-side navigation is the transition of pages using JavaScript rather than the default transition/navigation by the browser itself.

When you use an a tag to switch between pages, the browser does a full refresh of a page but when you use JavaScript, it won’t does not load the full page.

How to check if the Client-side navigation is working?

Refer to this official gif from Next.js.

  • First of all, add a link using Link component so that you can navigate to each page using link from another page.
  • Then, as you can see, you can change any CSS property of any element that exists on multiple pages.
    • In our case, we are changing the background-color of the html tag itself on both pages!
  • Now, simple visit both the pages and see if the background-color is there. If so, then the Client-side navigation is working.
  • If not, make sure you have added the Link tag to navigate to both pages.


Next.js also prefetches the code for the linked pages that are added using a Link component when they appear in the browser’s viewport. So, by the time you click on that Link, your code is already loaded and it gets served within seconds.

Code splitting

In Next.js, each page loads what’s necessary and that is achieved by splitting the code. That means, when you load one page, code for other pages is not served, which makes the initial rendering faster.

Code splitting helps create isolated pages so that if one page throws an error, other pages won’t get affected by it.

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
CREATE TABLE Examples in PostgreSQLPostgresHow to add new elements with swing animation using JavaScript and CSS?CSSThe basics of CSS Box modelCSSJavaScript arrays: a separate data type or Objects?JavaScriptHow to scroll contents of HTML body horizontally and vertically using JavaScript?JavaScriptHow to control file extensions with an .htaccess file?Miscellaneous