Building Blazing-Fast Websites with Next.js and Sanity.io

Rate this content
Bookmark

Join us for a hands-on workshop where we'll show you how to level up your React skills to build a high-performance headless website using Next.js, Sanity, and the JAMstack architecture. No prior knowledge of Next.js or Sanity is required, making this workshop ideal for anyone familiar with React who wants to learn more about building dynamic, responsive websites.


In this workshop, we'll explore how Next.js, a React-based framework, can be used to build a static website with server-side rendering and dynamic routing. You'll learn how to use Sanity as a headless CMS to manage your website’s content, create custom page templates with Next.js, use APIs to integrate with the CMS, and deploy your website to production with Vercel.


By the end of this workshop, you will have a solid understanding of how Next.js and Sanity.io can be used together to create a high-performance, scalable, and flexible website.

This workshop has been presented at React Summit 2023, check out the latest edition of this React Conference.

FAQ

Headless architecture refers to a setup where the front-end presentation layer is completely decoupled from the back-end content management system (CMS). The data is served to the site via an API, allowing developers to use any framework or technology for the front end while managing content separately in the CMS.

Using a headless CMS offers several benefits including being framework agnostic, which allows developers to use any front-end technology. It's highly customizable, supports SEO and performance optimizations, and the content can be reused across various digital platforms and devices efficiently.

To set up a repository for a Next.js and Sanity project, you typically fork and clone a starter repo, run 'npm install' to install dependencies, and use provided scripts to launch development environments for Storybook, the app, and Sanity.

Sanity is an API-based, headless CMS that allows for real-time editing and customization of content models. It supports a rich editor interface and provides a built-in preview functionality to see changes in real-time before publishing.

Next.js is a React framework used for building web applications. It supports features like static site generation, server-side rendering, and dynamic routing, which help in building fast and efficient web applications.

Deployment on Vercel for a Next.js application involves linking your GitHub repository with Vercel, setting up environment variables, and configuring webhooks to trigger rebuilds on content updates. Vercel automates the deployment process and provides a live URL for the hosted application.

Storybook is an open-source tool for developing UI components in isolation. It allows developers to build and test UI components interactively without needing to integrate them into a web app, making the development process faster and more efficient.

Data from Sanity can be queried in a Next.js project using Sanity's Grok query language. You can write queries to fetch specific data like page paths or content, which can then be used to dynamically generate pages or populate components in the application.

Nancy Du
Nancy Du
Nataliya Ioffe
Nataliya Ioffe
71 min
25 May, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This workshop covers building blazing fast websites with Next.js and Sanity. It explores the benefits of headless architecture and CMS tools like Sanity. The workshop guides participants through setting up the repo, working with Sanity and Next.js, and deploying to production on Vercel. Content modeling in headless CMS and schema creation in Sanity are explained. The workshop also covers using Grok to query content, connecting content with Next.js, and deploying to production with Vercel.

1. Introduction to the Workshop

Short description:

This is Building Blazing Fast Websites with Next.js and Sanity. Natalia Iaffe, a software developer at RangleIO, specializes in front-end development and has experience with headless architecture and CMS like Sanity and Contentful. Nancy, an associate director of digital strategy at Rangle, is also a developer with expertise in headless CMS projects. The workshop will cover the platforms used, setting up the repo, working with Sanity and Next.js, and deploying to production on Vercel. The website being built is for a fictional organization called Pangea, focused on gardening.

So welcome everybody. This is Building Blazing Fast Websites with Next.js and Sanity. Um, so let's get right into it. Just a little intro. My name is Natalia Iaffe. I am a software developer at RangleIO. I'm mostly specialized in the front end. And, uh, most of my work has been with partnering with organizations to like upgrade, um, our technical stacks to react and a lot of projects working, um, with headless architecture and, um, content editing abilities with, uh, with CMS like Sanity, Contentful, et cetera.

Um, yeah. Nancy. Yeah. Hey everyone. My name is Nancy. Um, I also work at Rangle along with Natalia. I am a associate director of digital strategy. Um, but I'm actually just a developer by trade. So I've been doing a lot of headless CMS work in the last year, year to two years. Um, a lot of work with Sanity Contentful. So super excited to be here today to kind of share a lot of our learnings, um, with all of you guys on how we implement headless CMS projects.

Yeah. So, uh, hopefully everybody's seeing my screen. Um, let me know if there's any issues with the zoom guys, but I'll go ahead and chat about, uh, just a little overview of what we're going through today. Um, cause there is quite a bit. Um, so first we'll talk about just kind of what we're building. Um, you have the link that we've sent in the chats to take a look at that right now. Um, we are going to go through the platforms that we're using sanity next for sell, um, as well as storybook, um, and talk a bit about headless architecture and why, um, why use it. Um, we're going to set up the repo. So we'll have a bit of a pause, uh, bathroom break, whatever you've already set up your repo, um, and, uh, give you the scripts to get, to get going. Um, then we're going to dive into sanity. We'll dive into like the pieces that, um, uh, that you need to understand to get set in sanity working. Um, and then we'll have a little pause to set up cause you'll need to get a sanity account and all these things. Um, so we'll have a bit of a pause to set that up and then go into some breakout rooms to configure, uh, to do some activities based off of kind of the set we've talked about, uh, and Nancy and I will be hopping in and out of breakout rooms. Um, so, uh, that should be fun. Um, then we'll go into talking about next JS, which I think some of you have some experience with so far. Some not. Um, we'll talk a bit about that, the site builder, how it powers our app. And we will also go into a little breakout room to like, um, render some of the components that we have in this repo on the page with Next. And then, uh, lastly, we are going to be deploying to production on Vercel. Um, and we'll do some breakout rooms there as well. Um, and then hopefully you'll have a whole working app, um, website that you can customize, um, to your pleasure later. So that's what we'll be kind of going through. And, um, we have some guided times here. Um, but if people are faster, slower, um, we'll kind of work. We'll, we'll see how it goes. Um, so let's chat about, um, what we are building. So, um, just to confirm everyone, Nancy did my screen slide over. Okay, great. So, um, everyone should have this link, but, uh, this is the actual website app that we are building. This is a fictional organization called Pangea, um, for all of your gardening needs. Um, so we're just kind of mirroring an organization website.

2. Introduction to Headless Architecture and Tools

Short description:

This website offers various services and provides all the tools to create a full app. Headless architecture separates the presentation layer from the content layer, allowing for framework agnostic development and customizability. Headless CMS tools are optimized for SEO and performance, and the decoupling of data and visuals enables content reuse across different channels. The CMS platform, like Sanity, manages content, while the site builder, like Next.js, combines content with React components to create a fast application. Sanity is an API-based headless CMS with a native preview functionality, and Next.js is great for static site generation and server-side rendering.

This website has, or this organization offers various services. Um, so we'll, you'll have all of the tools to create this full app by the end of this workshop. Um, the other piece of this is the actual sanity CMS authoring experience, which looks a bit like this. We'll dive into it more later. Um, but this is the author experience that we will be building. Have some screenshots and slides for you guys as well, just for reference later.

But let's dive into what is Headless Architecture? Um, if you've, uh, worked with Contentful before, you may know a little bit about this, but if not, um, headless with headless architecture, um, well, you may have heard of, um, various CMS's like, uh, um, WordPress or, um, Squarespace, which are kind of what we call like Headful, where on the platform itself, you build and create components, um, as well as edit content in the same platform. Often they have features that are tied to that platform that you need to use with headless architecture, which is kind of what we're going to be working with. That presentational visual layer is completely decoupled separated from the, um, content layer, meaning like the data, like the different headings you want to use for various components, things like that, um, completely separated. Um, and the data is served, um, to your site via an API from the CMS. So instead of having everything all in one platform, it's separated and just connected with API. So there's two parts of that. Um, we've got the CMS, um, where you manage your data, um, all of your content, images, all of that. Um, something like sanity, which we're using today, or Contentful as some of you might have that some experience with Contentful. And then we have a second part, which is a site builder, um, in our case, it includes, um, using Next.js, but you can use something like Gatsby, if you have some experience with that, um, a component library and page templates. Um, so that site builder will actually end up combining your content from your CMS, um, with your React components, uh, into a really fast, um, Next.js application. Um, so there are some benefits to going headless, um, over having everything all in one platform. First of all, especially, uh, for us, devs, uh, we really love that it is framework, uh, agnostic. So, um, you can be building in the presentation layer or the visuals, um, using any tool of your choice. So, um, if you prefer React, use React, if you prefer Angular, use Angular, Vue, et cetera. So, you can be building all of your components in the language that, um, that you know or that your dev team knows. Um, it's super customizable, um, you can build in, bring in your own components, you're not tied to what, like, a certain platform, you know, like WordPress or whatnot requires of you and you can build in, or you can bring in a bunch of third party libraries for a lot of various features. Um, your, uh, the headless CMS tools are, uh, super optimized for SEO and performance. Um, and like what the app that we're building today, I usually can, um, you leverage, uh, static site generation, which just makes the app super fast. Um, and one of the greatest benefits as well is that, um, since your, uh, data is completely separate from visuals, different platform, that same content can be used across all different kinds of channels and digital touch points like mobile, um, apps, um, VR, maybe in the future, um, and just web applications and websites. Um, because it's all served via API, um, from your, um, from your CMS. So those are some really, um, important benefits of going headless, um, just real quick, sometimes I'm a super visual person person. So, um, visualizing kind of how this journey looks is useful, um, for me. So, uh, in our case, going from the left, you can see our headless CMS circle there is Sandy authors, uh, content editors, marketers will input their content into that CMS platform and the, and the editor interface. And then that API, um, the, uh, CMS API sends that information, um, uh, as Jason to our site builder. In our case, again, we're using next JS. So the site builder gets that data and, um, combines with your component library to build the front end and then a bundle that it bundles that code, uh, and sends it to your distribution platform. In our case, we're going to be using for sale. Um, and in the end, as we know, when we deploy, um, your browser, all it sees is the beautiful HTML with s JS and your, um, really great app that you built. And then zooming in just a bit, um, on the headless, uh, CMS workflow starting on the left. Um, and we'll see this kind of in practice and also do this as well in breakout rooms, but like an author we'll be using the editor interface, um, to create content, published content. And again, all of that content is sent via API or retrieved from the API with as Dayson data to next. So these, um, little info graphics might be just helpful in the future to take a look at just to, um, cause visual they're a little bit more helpful for me at least. Um, so we can just go right into the platforms and tools that we've kind of been mentioning. Um, first I'll talk about sanity, which, um, a couple of you mentioned have not used before, um, is API based headless CMS. Um, you can use the APIs to manipulate, like retrieve and manipulate content. Um, and in our case, we're going to use, um, react to, um, render all of our content into like beautiful components. And then, um, in sanity, something that we really love is that has a native built in preview functionality so that a marketer or something goes into the CMS, they're making a change. Um, you should be able to, to see the change that you're making before going live. Um, and it's really easy to work with sanity, uh, with Next.js. So this is just a little homepage of sanity. You can definitely go ahead and explore if you like. Um, Next.js, um, is I what we're using for our site builder. Um, it's great for static site generation, um, server side rendering and dynamic routing. We'll talk a little bit more about that as well.

Watch more workshops on topic

Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
Fetch, useEffect, React Query, SWR, what else?
React Advanced Conference 2023React Advanced Conference 2023
102 min
Fetch, useEffect, React Query, SWR, what else?
Top Content
WorkshopFree
Ondrej Polesny
Ondrej Polesny
In this workshop, first, we’ll go over the different ways you can consume APIs in React. Then, we’ll test each one by fetching content from a headless CMS (with both REST and GraphQL) and checking in detail how they work.
While there is no advanced React knowledge required, this is going to be a hands-on session, so you’ll need to clone a preconfigured GitHub repository and utilize your preferred React programming editor, like VS Code.
You will learn:- What diverse data fetching options there are in React- What are advantages and disadvantages of each- What are the typical use cases and when each strategy is more beneficial than others
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
React Summit 2023React Summit 2023
139 min
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
Top Content
WorkshopFree
Matteo Frana
Matteo Frana
- React Bricks: why we built it, what it is and how it works- Create a free account- Create a new project with Next.js and Tailwind- Explore the directory structure- Anatomy of a Brick- Create a new Brick (Text-Image)- Add a title and description with RichText visual editing- Add an Image with visual editing- Add Sidebar controls to edit props (padding and image side)- Nesting Bricks using the Repeater component- Create an Image gallery brick- Publish on Netlify or Vercel- Page Types and Custom fields- Access Page meta values- Internationalization- How to reuse content across pages: Stories and Embeds- How to create an E-commerce with Products’ data from an external database and landing pages created visually in React Bricks- Advanced enterprise features: flexible permissions, locked structure, custom visual components
From Todo App to B2B SaaS with Next.js and Clerk
React Summit US 2023React Summit US 2023
153 min
From Todo App to B2B SaaS with Next.js and Clerk
WorkshopFree
Dev Agrawal
Dev Agrawal
If you’re like me, you probably have a million side-project ideas, some that could even make you money as a micro SaaS, or could turn out to be the next billion dollar startup. But how do you know which ones? How do you go from an idea into a functioning product that can be put into the hands of paying customers without quitting your job and sinking all of your time and investment into it? How can your solo side-projects compete with applications built by enormous teams and large enterprise companies?
Building rich SaaS products comes with technical challenges like infrastructure, scaling, availability, security, and complicated subsystems like auth and payments. This is why it’s often the already established tech giants who can reasonably build and operate products like that. However, a new generation of devtools are enabling us developers to easily build complete solutions that take advantage of the best cloud infrastructure available, and offer an experience that allows you to rapidly iterate on your ideas for a low cost of $0. They take all the technical challenges of building and operating software products away from you so that you only have to spend your time building the features that your users want, giving you a reasonable chance to compete against the market by staying incredibly agile and responsive to the needs of users.
In this 3 hour workshop you will start with a simple task management application built with React and Next.js and turn it into a scalable and fully functioning SaaS product by integrating a scalable database (PlanetScale), multi-tenant authentication (Clerk), and subscription based payments (Stripe). You will also learn how the principles of agile software development and domain driven design can help you build products quickly and cost-efficiently, and compete with existing solutions.
Building Reusable Server Components in NextJS
React Summit US 2023React Summit US 2023
88 min
Building Reusable Server Components in NextJS
Workshop
Will Bishop
Mettin Parzinski
2 authors
React continues to evolve their beta capability, React Server Components, and they're continuing to further develop them in partnership with frameworks like NextJS.In this workshop, attendees will learn what React Server Components are, how to effectively build and use them in NextJS, and focus on one of the major advantages of React/NextJS: reusability through components.We will also cover related beta technologies enabled by the `app` directory, such as nested layouts and server actions (alpha/experimental capability).Join us for this hands-on, 120 minute workshop!Technologies:
React, JavaScript/Typescript, NextJS, Miro

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Routing in React 18 and Beyond
React Summit 2022React Summit 2022
20 min
Routing in React 18 and Beyond
Top Content
Routing in React 18 brings a native app-like user experience and allows applications to transition between different environments. React Router and Next.js have different approaches to routing, with React Router using component-based routing and Next.js using file system-based routing. React server components provide the primitives to address the disadvantages of multipage applications while maintaining the same user experience. Improving navigation and routing in React involves including loading UI, pre-rendering parts of the screen, and using server components for more performant experiences. Next.js and Remix are moving towards a converging solution by combining component-based routing with file system routing.
A Practical Guide for Migrating to Server Components
React Advanced Conference 2023React Advanced Conference 2023
28 min
A Practical Guide for Migrating to Server Components
Top Content
Watch video: A Practical Guide for Migrating to Server Components
React query version five is live and we'll be discussing the migration process to server components using Next.js and React Query. The process involves planning, preparing, and setting up server components, migrating pages, adding layouts, and moving components to the server. We'll also explore the benefits of server components such as reducing JavaScript shipping, enabling powerful caching, and leveraging the features of the app router. Additionally, we'll cover topics like handling authentication, rendering in server components, and the impact on server load and costs.
The New Next.js App Router
React Summit 2023React Summit 2023
27 min
The New Next.js App Router
Watch video: The New Next.js App Router
Today's Talk is about the Next.js App Router, which has evolved over the years and is now a core feature of Next.js. The Talk covers topics such as adding components, fetching remote data, and exploring layouts. It also discusses submitting form data, simplifying code, and reusing components. The App Router allows for coexistence with the existing pages router and enables data fetching at the layout level using React Server Components.
You Don’t Know How to SSR
DevOps.js Conf 2024DevOps.js Conf 2024
23 min
You Don’t Know How to SSR
The Talk covers the speaker's personal journey into server-side rendering (SSR) and the evolution of web development frameworks. It explores the use of jQuery for animations in SSR, the challenges faced in integrating React with Umbraco, and the creation of a custom SSR framework. The Talk also discusses the benefits of Next.js and the use of serverless artifacts for deployment. Finally, it highlights the features of Astro, including its function per route capability.
How to properly handle URL slug changes in Next.js
TypeScript Congress 2022TypeScript Congress 2022
10 min
How to properly handle URL slug changes in Next.js
Top Content
This Talk explains how to handle URL slug changes in Next.js by using the getStaticPaths and getStaticProps methods. It covers implementing redirects and provides a solution to eliminate the need for editors to perform additional steps. The approach involves tracking URL slug changes and issuing proper redirects. The speaker encourages the audience to reach out with any questions or experiences with handling URL slugs.
Killing BFFs with GraphQL and Next.js
React Advanced Conference 2021React Advanced Conference 2021
21 min
Killing BFFs with GraphQL and Next.js
Top Content
This talk discusses the challenges and benefits of using Backend for Frontends (BFFs) and microservices in software development. It highlights how Next.js can simplify the creation of BFFs and unify the gateway for microservices. The talk also emphasizes the advantages of Next.js API routes in simplifying the development, deployment, and maintenance of APIs. It showcases the implementation of a BFF using Next.js and API routes, and the extension of API routes in an executable way. The speaker also mentions launching a course on using Next.js API routes for building a serverless GraphQL API.