Proposing Gatsby Cloud incremental builds with Strapi webhook
Recommend hooking Strapi's content update webhook to Gatsby Cloud's incremental build webhook; Gatsby Cloud then rebuilds only pages affected by changed content. Use gatsby-source-strapi and create pages with createPages to enable precise rebuilds of updated pages without a full site rebuild.
What Gatsby will do for you out of the box is rebuild whatever pages are affected by a data change, not blindly rerun every createPage call. Two pieces need to be in place for that to work:
- Your pages need to be created in a way that Gatsby can map a node to a URL, e.g. using
gatsby-node.js and context so that “post 123” only powers /blog/my-post.
- Your build needs to run in a mode that supports incremental builds, otherwise every change triggers a full rebuild.
A simple end‑to‑end setup looks like this:
- Source your Strapi content. With
gatsby-source-strapi in gatsby-config.js Gatsby will create nodes for your collection types:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-strapi`,
options: {
apiURL: process.env.STRAPI_API_URL,
collectionTypes: [`article`, `page`],
},
},
],
};
- Create one page per Strapi entry in
gatsby-node.js using the node ID or slug. That way Gatsby knows exactly which page depends on which piece of data:
// gatsby-node.js
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
{
allStrapiPage {
nodes {
id
slug
}
}
}
`);
result.data.allStrapiPage.nodes.forEach(({ id, slug }) => {
createPage({
path: `/${slug}`,
component: require.resolve(`./src/templates/page.js`),
context: { id }, // used in the page query
});
});
};
In src/templates/page.js you’d use pageQuery with $id so Gatsby can track the dependency.
-
Use a build system that supports incremental builds. On Gatsby Cloud this is automatic; on self‑hosted CI you can enable GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true and persist the .cache between runs. Gatsby will then only re‑run the page queries and HTML generation for pages whose data changed.
-
Trigger the build from Strapi. In the Strapi admin under Settings → Webhooks, add a new webhook that POSTs to your Gatsby build webhook URL and fires on “entry.update”/“entry.publish” for the relevant content types. If you’re on Gatsby Cloud, you’ll find a “Build Webhook” URL in your site settings; call that and it will run an incremental build. If you’re running your own builds, point the webhook at a small serverless function or CI endpoint that runs gatsby build with the cache restored.
With this in place, editing “About Us” in Strapi will emit a webhook, your build pipeline will kick off an incremental build, and only /about-us (and any other pages that directly consume that node) will be regenerated. There’s no need to rebuild the entire site on every change.