All basics

Framework

Next.js

The framework that holds an application together: pages, server code and delivery.

First released
2016
Developed by
Vercel
Licence
MIT, open source
Built on
React

01What it is

React is a library for building screens. On its own it does not say how an application is split into pages, how data gets from the database onto a screen, or how the finished application reaches a browser. Next.js answers those questions. It is a framework: a ready-made structure that a team fills with its own screens and logic.

Next.js is developed as open source by Vercel, a company in the US that also offers hosting for it. The code is published under the MIT licence, so anyone may use it, change it and run it wherever they like, without fees.

02What it takes care of

A business application needs the same basic parts again and again. Next.js provides them, so a project starts with the structure in place and the time goes into the parts that are specific to the client.

  • Pages and addresses: every page has its own address, such as /invoices or /customers/42, and the folder structure of the code decides which address shows which page.
  • Server code: functions that run only on the server, for example to read from the database, check permissions or call another system's API.
  • Rendering: pages can be prepared on the server and sent to the browser ready to show, either fresh for every request or prepared once in advance.
  • Sign-in and access checks: Next.js has fixed places where an application checks who is signed in before a page or a function runs.
  • Delivery: images are resized automatically, code is split into small pieces, and only what a page needs is loaded.

03How a page is built

When someone opens a page, Next.js runs the code for that page on the server. That code reads the data the page needs, for example the open invoices of one customer, and React turns it into the finished page. The browser receives the page ready to show and then takes over, so buttons, forms and filters react immediately.

Data that a screen does not need stays on the server. If an invoice record contains an internal note, the browser never receives it unless a page is written to show it. Passwords for databases and keys for other services are only ever used on the server.

Pages whose content rarely changes, such as this article, can be prepared once when the application is built. Next.js then serves the finished file, which is about as fast as a website can be.

04An example from a business application

Take a customer portal where clients see their open tickets and download invoices. In Next.js this is one project with a few folders: one page for the ticket list, one for a single ticket, one for invoices, and a server function that creates a new ticket when a client submits the form.

The ticket list is rendered on the server, after a check that the person signed in belongs to the company whose tickets are being shown. Downloading an invoice goes through a server function that checks the same permission before it hands out the file. The code for these checks sits next to the pages it protects, which makes it easy to review.

05Alternatives

Several frameworks solve similar problems. Each is a reasonable choice in the right setting.

  • Remix and React Router: also built on React, with a different approach to loading data and forms.
  • Nuxt: plays the same role for Vue, another library for building screens.
  • SvelteKit: the framework for Svelte, which needs less code in the browser.
  • Angular: a complete framework from Google, common in large companies.
  • Classic server frameworks such as Laravel (PHP), Django (Python) or Ruby on Rails: they render pages on the server and are strong for data-heavy applications, with a separate language from the browser code.

06What to look out for

Next.js itself costs nothing. The costs come from hosting, and they depend on how much the application is used. For an internal tool with a few dozen users they are usually small; for a public site with a lot of traffic they need watching.

Next.js moves quickly. A new major version appears roughly once a year, and older applications have to be updated now and then. That is normal maintenance, and it is easier when the application has automated tests.

Some features work best on Vercel's own hosting. Next.js also runs on other providers, for example on Microsoft Azure, AWS or a company's own servers, but a few conveniences have to be set up by hand there. It is worth deciding on hosting early.

07How we use it

All our applications are Next.js projects, this website included. We write them in TypeScript, build the screens with React and keep the data in Postgres.

We usually host on Vercel in Frankfurt, in an account that belongs to the client. Every proposed change to the code gets its own preview address, so a change can be looked at in the browser before it goes live. Our automated tests check on every change that the application still builds.

Frequently asked questions

Are we tied to Vercel if our application uses Next.js?

No. Next.js is open source and runs on other hosting providers and on your own servers. Vercel is the most convenient place to run it, and we usually start there, but a move is possible.

Is Next.js suitable for internal tools, or only for websites?

Both. It is used for public websites, online shops and internal applications with logins and permissions. Most of what we build with it sits behind a login.

What happens when a new version comes out?

Nothing breaks on its own; the application keeps running on the version it was built with. Updating to a new version is a planned piece of work, usually small, and the automated tests show whether anything is affected.

Will other developers be able to work on our application?

Yes. Next.js is one of the most widely used frameworks for React, so many developers know it. The structure is the same from project to project, which makes it easier for someone new to find their way.

Tell us what your software should do.

Start a conversation