These integration guides are not official documentation and the Strapi Support Team will not provide assistance with them.
Gatsby creates fast websites by combining React with GraphQL to pull data from various sources like Strapi. It pre-renders pages during build time, delivering static HTML files that load quickly while maintaining security through Jamstack principles.
Gatsby's plugin ecosystem extends functionality while preserving performance. It automatically handles technical optimizations like code splitting, image optimization, and resource prefetching to improve Core Web Vitals.
Want to dive deeper? Check out the official Gatsby documentation.
The Strapi-Gatsby combination delivers exceptional value for developers seeking performance and flexibility. Integrating Gatsby with Strapi continues to gain popularity for good reason.
This isn't just theoretical.
ESC Nasa built a lightning-fast platform for showcasing projects with this combo.
Combining Strapi with Gatsby gives you speed and flexibility without the headaches. Here's how to integrate these powerful tools.
Before diving in, you'll need:
1
npx create-strapi-app my-strapi-project1
2
cd my-strapi-project
npm run develop
http://localhost:1337/admin and create your content types and sample content.1
npx gatsby new my-gatsby-site1
cd my-gatsby-site1
npm install gatsby-source-strapi gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-remark gatsby-transformer-sharp.env.development file in your Gatsby project root:1
2
STRAPI_TOKEN=<YOUR_STRAPI_API_TOKEN>
GATSBY_STRAPI_API_URL=http://localhost:1337
<YOUR_STRAPI_API_TOKEN> with the API token generated in Strapi. gatsby-source-strapi plugin in your gatsby-config.js:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
});
module.exports = {
plugins: [
{
resolve: `gatsby-source-strapi`,
options: {
apiURL: process.env.GATSBY_STRAPI_API_URL,
accessToken: process.env.STRAPI_TOKEN,
collectionTypes: ['article', 'category'],
singleTypes: ['homepage'],
},
},
// Other plugins...
],
}1
gatsby develophttp://localhost:8000/___graphql to test your queries. For example:1
2
3
4
5
6
7
8
9
10
11
{
allStrapiArticle {
nodes {
title
content
category {
name
}
}
}
}
src/pages/articles.js:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React from "react"
import { graphql } from "gatsby"
const ArticlesPage = ({ data }) => (
<div>
<h1>Articles</h1>
{data.allStrapiArticle.nodes.map(article => (
<div key={article.id}>
<h2>{article.title}</h2>
<p>{article.content}</p>
</div>
))}
</div>
)
export const query = graphql`
query ArticlesQuery {
allStrapiArticle {
nodes {
id
title
content
}
}
}
`
export default ArticlesPage
To optimize images from Strapi, use gatsby-plugin-image with gatsby-plugin-sharp. Here's how to display an image from Strapi:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from "react"
import { graphql } from "gatsby"
import { GatsbyImage, getImage } from "gatsby-plugin-image"
const ArticlePage = ({ data }) => {
const article = data.strapiArticle
const image = getImage(article.cover.localFile)
return (
<div>
<h1>{article.title}</h1>
<GatsbyImage image={image} alt={article.title} />
<p>{article.content}</p>
</div>
)
}
export const query = graphql`
query ArticleQuery($id: String!) {
strapiArticle(id: { eq: $id }) {
title
content
cover {
localFile {
childImageSharp {
gatsbyImageData(width: 800)
}
}
}
}
}
`
export default ArticlePage
When ready to deploy your Gatsby site:
1
gatsby buildpublic directory to your hosting platform (Netlify, Vercel, GitHub Pages, etc.).Remember to set up environment variables on your hosting platform to match those in your .env.development file.
This setup gives you the best of both worlds—flexible content management through Strapi with Gatsby's static site generation for blazing speed and SEO benefits.
Want your site to update automatically when content changes? Set up webhooks to trigger Gatsby builds when Strapi content updates. Find details on setting up webhooks in the Strapi documentation.
Let's look at something real—a portfolio website built with Gatsby and Strapi by coding educator John Smilga. It's the perfect jumping-off point if you're building your own developer or freelancer portfolio.
This portfolio project shows how integrating Gatsby with Strapi creates a dynamic, high-performance website that's also dead simple to manage. It's like having your cake and eating it too.
What makes it special:
Under the hood, this project runs on Gatsby v3 and Strapi with some clever implementation choices:
What makes this combo so powerful?
"Integrating Gatsby with Strapi allows developers to quickly build very fast static websites and apps. Both use JavaScript and integrate smoothly. This combination empowers developers to create high-performance sites while giving content creators an easy-to-use interface for updates."
Want to build something similar?
This approach lets you focus on what matters—showcasing your work, not fighting with your website.
For step-by-step guidance, check out the official Strapi documentation.
If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at Strapi's Discord Open Office Hours Monday through Friday at 12:30 pm - 1:30 pm CST: Strapi Discord Open Office Hours
For more details, visit the Strapi documentation and Gatsby documentation.