Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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 eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
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 : 9781801079877
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Feb 28, 2022
Length: 366 pages
Edition : 1st
Language : English
ISBN-13 : 9781801079877
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

Most Recent
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
Most Recent

Filter reviews by




weworkbetter Nov 09, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
In a nutshell this book is a perfect starting point into the world of production-grade full stack web development especially using Nextjs.The focus of this book is the application performance and the developer experience. The author writes about it in great detail with a lot of enthusiasm, full of conviction, solid understanding and great hands-on experience in Nextjs.Just like Nextjs framework targets the entire life cycle of building the production grade web applications, the author walks the readers through the entire life cycle of building web applications. Along the way, he shares a lot of valuable advice and great directions, again it is all based on his own experience as a proven Nextjs developer.Please do not expect this book alone will give everything to study full stack development, rather it must be seen as a perfect guide which walks the reader through the whole developmental life cycle in great breadth and length. One must also follow the pointers and additional references given in it.Notes:There are some inactive urls given in the book, this must be tackled by the readers by their own individual commitment which is the only additional effort to be traded to make use of this great compilation.This book is based on the page router, and the latest is the app router. However, to me the whole point is in the rendering strategies in Nextjs which is independent of the two routers.Thanks and RegardsWeDoTheBest4You
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
Simon Dec 06, 2022
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Some examples don't line up with what's in the text forcing you to close the gaps yourself. Additionally, examples that call URLs that don't exist anymore. Some of the examples use tags that are deprecated as well. Super disappointing to find out this book is this severely out of date after getting through a third of 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
George Oct 02, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Could be a great book, but I will not suggest buying it unless these links are fixed, as you simply would not be able to follow the guides.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.