Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Real-World Next.js
Real-World Next.js

Real-World Next.js: Build scalable, high-performance, and modern web applications using Next.js, the React framework for production

eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Real-World Next.js

Chapter 1: A Brief Introduction to Next.js

Next.js is an open source JavaScript web framework for React that ships with a rich set of features out of the box, such as server-side rendering, static site generation, and incremental static regeneration. These are just some of the many built-in components and plugins that make Next.js a framework ready for both enterprise-level applications and small websites.

This book aims to show you the full potential of this framework while building real-world applications and use cases, such as e-commerce websites and blogging platforms. You will learn the basics of Next.js, how to choose between different rendering strategies and deployment methodologies, and different tips and approaches for making your web application both scalable and maintainable.

In this chapter, we will cover the following topics:

  • Introduction to the Next.js framework
  • Comparing Next.js with other popular alternatives
  • Differences between Next.js and client-side React
  • Anatomy of a default Next.js project
  • How to develop Next.js applications using TypeScript
  • How to customize both Babel and webpack configurations

Technical requirements

To get started with Next.js, you need to install a couple of dependencies on your machine.

First of all, you need to install Node.js and npm. Please refer to this blog post if you need a detailed guide for installing them: https://www.nodejsdesignpatterns.com/blog/5-ways-to-install-node-js.

If you don't want to install Node.js on your local machine, some online platforms will let you follow the code examples in this book using an online IDE for free, such as https://codesandbox.io and https://repl.it.

Once you have both Node.js and npm installed (or you're using an online environment), you'll only need to follow the instructions displayed in each section of this book for installing the required project-specific dependencies using npm.

You can find complete code examples on GitHub under the following repository: https://github.com/PacktPublishing/Real-World-Next.js. Feel free to fork, clone, and edit this repository for any experimentation with Next.js.

Introducing Next.js

Web development has changed a lot over the last few years. Before the advent of modern JavaScript frameworks, creating dynamic web applications was complex, and it required many different libraries and configurations to make them work as expected.

Angular, React, Vue, and all the other frameworks have enabled the web to evolve very quickly, and brought with them some very innovative ideas to frontend web development.

React, in particular, was created by Jordan Walke at Facebook and was heavily influenced by the XHP Hack Library. XHP allowed Facebook's PHP and Hack developers to create reusable components for the frontend of their applications. The JavaScript library became open source in 2013 and forever changed how we build websites, web apps, native apps (with React Native later on), and even VR experiences (with React VR). As a result, React has quickly become one of the most loved and popular JavaScript libraries, with millions of websites using it in production for many different purposes.

There was just one problem: by default, React runs on the client side (meaning that it runs on the web browser), so a web application written entirely with that library could negatively affect Search Engine Optimization (SEO) and initial load performance, as it takes some time to be correctly rendered on screen. In fact, to display the complete web app, the browser had to download the entire application bundle, parse its content, then execute it and render the result in the browser, which could take up to a few seconds (with very large applications).

Many companies and developers started investigating how to pre-render the application on the server, letting the browser display the rendered React app as plain HTML, making it interactive as soon as the JavaScript bundle has been transferred to the client.

Then, Vercel came up with Next.js, which has turned out to be a game-changer.

Since its first release, the framework has provided many innovative features out of the box, such as automatic code-splitting, server-side rendering, file-based routing systems, route pre-fetching, and so on. Next.js showed how easy it should be to write universal web applications by allowing developers to write reusable code for both client and server sides and making very complex tasks (such as code-splitting and server-side rendering) effortless to implement.

Today, Next.js provides tons of new features out of the box, such as the following:

  • Static site generation
  • Incremental static generation
  • Native TypeScript support
  • Automatic polyfills
  • Image optimization
  • Support for internationalization
  • Performance analytics

All this, along with many other great features that we'll look at in depth later on in this book.

Today, Next.js is used in production by top-level companies such as Netflix, Twitch, TikTok, Hulu, Nike, Uber, Elastic, and many others. If you're interested, you can read the complete list at https://nextjs.org/showcase.

Next.js showed how versatile React could be for building many different applications at any scale, and it's not surprising to see it in use by both big companies and small start-ups. By the way, it is not the only framework that lets you render JavaScript on the server side, as we'll see in the next section.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Develop scalable web applications using Next.js
  • Use Next.js as a frontend for existing backends and e-commerce websites and understand how to implement it with any headless CMS
  • Deploy Next.js on different platforms, such as Vercel, DigitalOcean, and AWS, or on your own server

Description

Next.js is a scalable and high-performance React.js framework for modern web development and provides a large set of features, such as hybrid rendering, route prefetching, automatic image optimization, and internationalization, out of the box. If you are looking to create a blog, an e-commerce website, or a simple website, this book will show you how you can use the multipurpose Next.js framework to create an impressive user experience. Starting with the basics of Next.js, the book demonstrates how the framework can help you reach your development goals. You'll realize how versatile Next.js is as you build real-world applications with step-by-step explanations. This Next.js book will guide you in choosing the right rendering methodology for your website, securing it, and deploying it to different providers, all while focusing on performance and developer happiness. By the end of the book, you'll be able to design, build, and deploy modern architectures using Next.js with any headless CMS or data source.

Who is this book for?

This book is for web developers who want to improve their React skills by building scalable and maintainable full-stack applications using the modern Next.js web framework. Intermediate-level knowledge of ES6+, React, Node.js, and REST is assumed.

What you will learn

  • Get up to speed with Next.js essentials and learn how to build apps quickly
  • Understand how to create scalable Next.js architectures
  • Choose between different rendering strategies, such as client-side rendering (CSR), static site generation (SSG), server-side rendering (SSR), and incremental static regeneration (ISR)
  • Write unit tests and integration tests in your Next.js application
  • Discover the powerful routing system and Next.js' built-in components
  • Design and build modern architectures with Next.js using GraphCMS or any headless CMS

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 28, 2022
Length: 366 pages
Edition : 1st
Language : English
ISBN-13 : 9781801073493
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 28, 2022
Length: 366 pages
Edition : 1st
Language : English
ISBN-13 : 9781801073493
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 99.97
React Projects
€29.99
Full-Stack Web Development with GraphQL and React
€36.99
Real-World Next.js
€32.99
Total 99.97 Stars icon

Table of Contents

18 Chapters
Part 1: Introduction to Next.js Chevron down icon Chevron up icon
Chapter 1: A Brief Introduction to Next.js Chevron down icon Chevron up icon
Chapter 2: Exploring Different Rendering Strategies Chevron down icon Chevron up icon
Chapter 3: Next.js Basics and Built-In Components Chevron down icon Chevron up icon
Part 2: Hands-On Next.js Chevron down icon Chevron up icon
Chapter 4: Organizing the Code Base and Fetching Data in Next.js Chevron down icon Chevron up icon
Chapter 5: Managing Local and Global States in Next.js Chevron down icon Chevron up icon
Chapter 6: CSS and Built-In Styling Methods Chevron down icon Chevron up icon
Chapter 7: Using UI Frameworks Chevron down icon Chevron up icon
Chapter 8: Using a Custom Server Chevron down icon Chevron up icon
Chapter 9: Testing Next.js Chevron down icon Chevron up icon
Chapter 10: Working with SEO and Managing Performance Chevron down icon Chevron up icon
Chapter 11: Different Deployment Platforms Chevron down icon Chevron up icon
Part 3: Next.js by Example Chevron down icon Chevron up icon
Chapter 12: Managing Authentication and User Sessions Chevron down icon Chevron up icon
Chapter 13: Building an E-Commerce Website with Next.js and GraphCMS Chevron down icon Chevron up icon
Chapter 14: Example Projects and Next Steps for Learning More Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(11 Ratings)
5 star 63.6%
4 star 9.1%
3 star 18.2%
2 star 0%
1 star 9.1%
Filter icon Filter
Top Reviews

Filter reviews by




George Jun 08, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Explains the core concepts well after which you are given a wealth of knowledge of how to leverage the framework in a wide range of applications. As someone who develops with Next.js everyday, I can foresee myself returning to the book to reexplore concepts and ideas that can be implemented in to my future projects.
Amazon Verified review Amazon
Michael D. Sep 26, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's hit-or-miss with technical books, so I was pleasantly surprised that this book backfilled the gaps in my knowledge of Next.js without going overboard and trying to cram every possible Next.js topic into one book. Probably like most developers approaching this book, I'm already seasoned with using React, most other topics related to frontend development, and am comfortable with both consuming and writing APIs. I got (more) into using Next.js in the past year, and had looked up enough info in their docs to get things done, but knowing full well that even though I was getting things to work, I probably wasn't doing it in the "best practices" way with respect to Next.js. I was basically taking my React knowledge and just creating components in a Next.js framework without really leveraging Next.js as a server-side rendering tool. So if that's you too, I'm not going to judge! The book talks about the must-knows of server-side rendering, static site rendering, folder structures, and moves into testing, hosting environments, and example sites that could be built with Next.js. Judging the book on just that content, I give it 5 stars. I know other reviewers mentioned that the API that is mentioned in the book isn't working or wasn't working. I didn't find myself needing to do anything with the book's code and/or API as I was just using the book to backfill knowledge and look at the printed code examples to reinforce a topic. My review is based on the structure and content of the book, but yeah, I can see that a book that alludes to an API, but the API isn't working, could be a deal breaker. I'm still giving the book the full 5 stars as it served my needs and I improved from having invested time and money in it.
Amazon Verified review Amazon
Marcelo Oct 07, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Every line in this books delivers a lot of value. Thought opinionated about how to structure your applications around the framework, the author gives clear insights into the reasoning behind each of his decisions. Provides a deep analysis on different rendering strategies and how to solve recurring problems in commercial applications that might get you ahead of time when working on similar projects.
Amazon Verified review Amazon
Choudhry May 05, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great guide easy to follow the online resources are easy to download/clone.One thing I really like about this book is it's not just random stuff you won't really build outside for the sake of it. You learn to work with CMS systems and build things you would build like a store and how to do authentication.
Amazon Verified review Amazon
No Mar 01, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
There's tons of effort gone into putting this book together and it really shows! Michele's gone into a deep dive to provide accurate information, especially when covering static site generation, sourcing data via GraphQL APIs, working with eCommerce and GraphCMS, and talking about choosing Next.js over other alternatives (incl. use cases)Really enjoyed reading this and found it very insightful.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.