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.

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
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
Crash course into Astro and Storyblok
React Day Berlin 2023React Day Berlin 2023
119 min
Crash course into Astro and Storyblok
WorkshopFree
Arisa Fukuzaki
Arisa Fukuzaki
Headless architecture has gained immense popularity in recent years for its ability to decouple the frontend and backend, empowering developers to create engaging, interactive, and scalable web applications. 
In this workshop, we will quickly take a dive into the Headless World and Architecture. 
Additionally, we will build a blog website super quickly using Storyblok, a headless CMS that offers a real-time preview feature with nestable component approach, and Astro (3.0) which is already creating a buzz with the new app directory. 
- Master headless CMS fundamentals- Master an Astro & headless CMS approach- Use Atomic design in your Astro & Storyblok application- Creating pages, adding content and understanding how the dynamic routing works with headless
Full Stack GraphQL In The Cloud With Neo4j Aura, Next.js, & Vercel
GraphQL Galaxy 2021GraphQL Galaxy 2021
161 min
Full Stack GraphQL In The Cloud With Neo4j Aura, Next.js, & Vercel
WorkshopFree
William Lyon
William Lyon
In this workshop we will build and deploy a full stack GraphQL application using Next.js, Neo4j, and Vercel. Using a knowledge graph of news articles we will first build a GraphQL API using Next.js API routes and the Neo4j GraphQL Library. Next, we focus on the front-end, exploring how to use GraphQL for data fetching with a Next.js application. Lastly, we explore how to add personalization and content recommendation in our GraphQL API to serve relevant articles to our users, then deploy our application to the cloud using Vercel and Neo4j Aura.

Table of contents:
- Next.js overview and getting started with Next.js
- API Routes with Next.js & building a GraphQL API
- Using the Neo4j GraphQL Library
- Working with Apollo Client and GraphQL data fetching in Next.js
- Deploying with Vercel and Neo4j Aura

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
Concurrent React and Server Components are changing the way we think about routing, rendering, and fetching in web applications. Next.js recently shared part of its vision to help developers adopt these new React features and take advantage of the benefits they unlock.In this talk, we’ll explore the past, present and future of routing in front-end applications and discuss how new features in React and Next.js can help us architect more performant and feature-rich applications.
The New Next.js App Router
React Summit 2023React Summit 2023
27 min
The New Next.js App Router
Next.js 13.4 recently released the stable version of the "App Router" – a transformative shift for the core of the framework. In this talk, I'll share why we made this change, the key concepts to know, and why I'm excited about the future of React.
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
Server Components are the hot new thing, but so far much of the discourse around them has been abstract. Let's change that. This talk will focus on the practical side of things, providing a roadmap to navigate the migration journey. Starting from an app using the older Next.js pages router and React Query, we’ll break this journey down into a set of actionable, incremental steps, stopping only when we have something shippable that’s clearly superior to what we began with. We’ll also discuss next steps and strategies for gradually embracing more aspects of this transformative paradigm.
You Don’t Know How to SSR
DevOps.js Conf 2024DevOps.js Conf 2024
23 min
You Don’t Know How to SSR
A walk-through of the evolution of SSR in the last twelve years. We will cover how techniques changed, typical problems, tools you can use and various solutions, all from the point of view of my personal experience as a consumer and maintainer.
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
If you're using a headless CMS for storing content, you also work with URL slugs, the last parts of any URL. The problem is, content editors are able to freely change the slugs which can cause 404 errors, lost page ranks, broken links, and in the end confused visitors on your site. In this talk, I will present a solution for keeping a history of URL slugs in the CMS and explain how to implement a proper redirect mechanism (using TypeScript!) for dynamically generated pages on a Next.js website.

Add to the talk notes: https://github.com/ondrabus/kontent-boilerplate-next-js-ts-congress-2022 
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
Frontend applications are getting more and more complicated, often delivering far more than just a UI. With this growing complexity comes a growing need for knowledge from the developers creating it, as they have to deal with matters like state-management, authorization, routing and more. In this talk, I'll show you how to use GraphQL in your Next.js application to create a data layer for your application, that exists between your frontend and your backend. In this data layer, you can handle complex matters to help you to keep your frontend application clean and "stupid".