Next.js Quick Start Guide
Server-side rendering done right
Kirill Konshin
BIRMINGHAM - MUMBAI
Next.js Quick Start Guide
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Amarabha Banerjee
Acquisition Editor: Reshma Raman
Content Development Editor: Roshan Kumar
Technical Editor: Shweta Jadhav
Copy Editor: Safis Editing
Project Coordinator: Hardik Bhinde
Proofreader: Safis Editing
Indexer: Priyanka Dhadke
Graphics: Jason Monteiro
Production Coordinator: Arvindkumar Gupta
First published: July 2018
Production reference: 1230718
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78899-366-1
www.packtpub.com
To my parents, family, and to all friends for their love and support.
Kirill Konshin
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Kirill Konshin is the principal software developer at RingCentral, the world's leading Cloud communications provider. He is a highly experienced professional in full-stack web engineering with more than 10 years of experience, proficient in all the most recent web technologies. He is also an active open source contributor to React-related projects. You can follow him on Medium.
About the reviewer
Chris van Rensburg has been involved in JavaScript since the very birth of the language from its early progenitor, LiveScript, that was developed in the 90s by Netscape. While then working for a small start-up in San Mateo, Chris was part of a pitch to Netscape executives on how web pages could be made interactive by the addition of event handler attributes to HTML tags for invoking actions. Chris went on to develop high-level JavaScript frameworks, culminating in the UIZE JavaScript Framework.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
This book guides developers from building simple, single-page applications to fully-fledged, scalable, and reliable client-server infrastructures that enable code sharing between client and server, universal modules, and server-side rendering. This book explains the best practices for building sites using Next.js, enabling readers to build SEO-friendly and superfast websites.
Next.js is a rising star of modern JavaScript. It is a powerful tool that can save a lot of time by doing all the under-the-hood processing required to bring a universal applications to life.
Who this book is for
This book is for skilled professionals seeking a comprehensive guide on how to build a flexible, scalable, and well-designed universal JavaScript application with server-side rendering capabilities using Next.js.
This book will also help developers discover what server-side rendering is and get to grips with what the bleeding edge of the technology has to offer in its current state.
We will guide users through the following challenges:
- Performance of single-page applications
- SEO
- Blazing-fast rendering of the initial page when a customers visit the website
- Maximum reuse of modules on client and server sides
- What server-side rendering is, how it helps, and how to do it right
What this book covers
, Introduction to Server-Side Rendering and Next.js, explains the basics of frontend development, problem definition, what frameworks are available, and what problems they solve, what server-side rendering is, and why it is needed. This chapter explains the benefits of Next.js.
, Next.js Fundamentals, explains the fundamental things about building JavaScript apps and React apps in particular. It guides the reader through installation and the development/build life cycle of the Next.js application. You'll learn how to create website pages and wire them together through the website navigation. After that, styling and rich content approaches are explained.
, Next.js Configuration, will go into Webpack and Babel. It is a small chapter but definitely one worth mentioning, because it is very useful for advanced cases.
, Next.js Data Flow, explains the purpose of all JS applications: talking to the backend. We show different approaches, including vanilla Next JS flow, with no frameworks, which is useful for understanding the essence of interaction before moving on to look at more advanced techniques.
, Application Life Cycle Handlers and Business Logic, demonstrates the most important and frequently asked questions about React-based application architecture and patterns. We explain how to design and implement the core modules, such as logging and authentication, and then move on to more complex solutions for access control and business rules management.