Gatsby Build Times are Slow: Fix or Migrate?

Hero image for Gatsby Build Times are Slow: Fix or Migrate? Image by Mathew Schwartz.
Hero image for 'Gatsby Build Times are Slow: Fix or Migrate?' Image by Mathew Schwartz.

In Brief

Slow Gatsby builds are a signal that we should measure before choosing a direction. If one plugin, query, image step, or cachesetting is the bottleneck, fixing Gatsby may be enough. If publishing, preview, CMS sourcing, CI cost, and rebuild volume are all working against the team, migration becomes a platform decision rather than a build tweak.

Slow Gatsby builds do not automatically mean you should migrate, but they do mean the platform is asking for a decision.

Sometimes the right answer is to optimise the Gatsby build. Remove unused plugins, reduce GraphQL query weight, stop clearing caches, slim image processing, and fix the source plugin or page creation work that is making every deployment crawl.

Sometimes the build is only the most visible symptom. The real problem is that content publishing is too slow, preview is awkward, the CMS model has outgrown the site, plugins are brittle, CI is expensive, and every release feels like negotiating with the platform.

At that point, a Gatsby to Next.js migration may be a better investment than another round of build tuning. The judgement is knowing which problem you actually have.


Start by Measuring Where the Time Goes

Do not start with "Gatsby is slow". Start with the build trace.

Separate time spent in content sourcing, schema creation, page creation, GraphQL queries, image processing, JavaScript bundling, HTML generation, cache restore, dependency installation, and deployment upload. A 20minute build caused by image processing is a different problem from a 20minute build caused by pulling too much CMS data on every run.

Gatsby's own improving build performance guide is practical here. It calls out plugin configuration, query size, cache reuse, content sourcing, schema creation, image processing, and hardware as separate levers. That matters because some slow builds can be improved without changing framework.

The first question is not "should we migrate?" It is "what is Gatsby doing for those minutes?"


Fix Gatsby When the Problem is Narrow

If the site is healthy and the build issue is specific, fix it in place.

Good candidates for optimisation include:

  • unused plugins still running during build
  • gatsby clean wiping useful cache state in CI
  • page creation queries pulling full content when IDs would do
  • page queries fetching fields templates never render
  • image transformations running for lowvalue pages
  • expensive formats or placeholders used everywhere
  • stale source plugin versions
  • local development building far more pages than engineers need

The Gatsby image documentation is a reminder that image behaviour is not just one component. Placeholder strategy, formats, responsive variants, and source images all affect build cost. If image processing is the bottleneck, migration might be overkill.

Fixing Gatsby is usually the right call when editors are happy, preview is acceptable, plugins are maintained, the CMS model is sound, and build time is the main pain.


Treat Content Volume as a Structural Signal

Content volume changes the nature of the problem.

A build that was fine with 300 pages can become painful with 5,000 pages, multiple locales, large media libraries, and complex CMS references. Gatsby can handle large sites, but not every Gatsby implementation was designed for that growth.

Look at:

  • number of pages created
  • number of CMS entries fetched
  • locales or markets included
  • reference depth
  • rich text transformations
  • image count and size
  • page templates with the most query work
  • content types that change most often

If the site rebuilds thousands of mostly unchanged pages because one article changed, the issue may be the build model rather than one slow query. That is where Next.js rendering options, ISR, and routelevel caching can become relevant. Vercel's ISR documentation explains the model of serving cached content whilst regenerating routes without rebuilding the entire site.

Do not assume ISR is automatically the answer. Use it when it matches the publishing pattern.


Check the Source Plugin and CMS Relationship

Many slow Gatsby builds are really CMS integration problems.

The source plugin may be fetching more content than the site needs. It may pull every locale, every content type, every asset, and every linked entry because the original setup was convenient. It may also be fighting rate limits, schema inference, or inconsistent data.

If Contentful is involved, inspect whether the Gatsby site still needs the Contentful model it is pulling. Old content types, unused fields, deeply nested references, and rich text rendering work can all make builds slower and more fragile. The article on rendering Contentful rich code snippets in Gatsby is a small example of how Contentful and Gatsby concerns can become intertwined.

If the team is also considering Sanity, keep that decision explicit. A framework migration and a CMS migration can fit together, but they are not the same task. Combining them without a plan is how teams lose track of content, preview, redirects, and launch risk.


Preview Friction is a Migration Signal

Build time is not the only form of slowness.

If editors cannot trust preview, every content change takes longer. If preview depends on a full build, a delayed deploy, or a partial workaround, the build problem becomes an editorial workflow problem. If teams are batching content changes because publishing one change is too slow, the platform is shaping behaviour.

That does not automatically mean Gatsby must go. It does mean the fix has to cover the publishing path, not only CI duration.

Ask:

  • Can editors preview draft content reliably?
  • Can they preview the page types they actually edit?
  • Are content updates visible quickly enough?
  • Does preview use the same content model as production?
  • Are failed builds blocking publishing?
  • Are editors working around the platform?

If the answer is mostly no, headless CMS integration may be the real problem area.


CI Constraints Can Distort the Decision

Slow builds feel worse when CI is already under pressure.

Dependency installation, cache restore, memory limits, CPU constraints, image processing, source plugin calls, and deployment upload can all combine into a release process that feels unstable. Sometimes moving to a larger machine or fixing cache persistence buys enough headroom. Sometimes the pipeline is revealing that the architecture is doing too much work per change.

This is where deployment debugging overlaps with migration planning. If a future Next.js deployment will run on Vercel, the target pipeline needs to be tested against real content, not just a small prototype.

Do not migrate because CI is irritating. Migrate because the current release model no longer fits the site's scale and publishing needs.


Migrate When the Pain is Systemic

A Gatsby to Next.js migration becomes easier to justify when several problems line up.

The stronger migration case looks like this:

  • builds are slow even after obvious optimisation
  • preview is unreliable or too slow for editors
  • plugins are brittle or blocking upgrades
  • the CMS model is tightly coupled to old templates
  • content changes need faster publication than full rebuilds allow
  • deployment confidence is low
  • SEO and routing need a more controlled migration anyway
  • the team wants a clearer rendering model for the next phase

That is the moment to read a Gatsby to Next.js migration checklist and plan the move properly. The migration should remove build pain, not recreate it with different tools.


A Practical Decision Process

Use a short diagnostic before committing to either path.

  1. Measure the current build stages and identify the biggest costs.
  2. Remove obvious Gatsby waste and rerun the build.
  3. Check whether the CMS and preview workflow are part of the pain.
  4. Estimate the cost of fixing Gatsby for the next 12 months.
  5. Estimate the cost and risk of moving to Next.js.
  6. Decide whether the business needs a build fix, a platform migration, or a staged plan.

If a twoday optimisation reduces builds from 20 minutes to six and editors are otherwise happy, take the win. If build time is only one symptom of a brittle content platform, another optimisation sprint may only delay the real decision.


Wrapping Up

Slow Gatsby builds are a signal, not a verdict.

Fix Gatsby when the bottleneck is narrow and the wider platform still works. Consider migration when build time, preview, content volume, source plugins, CI limits, and editorial workflow all point to a site that has outgrown its original model.

The best decision is not the one that sounds most modern. It is the one that leaves the team with faster releases, clearer content ownership, and fewer hidden risks.

Key Takeaways

  • Measure build stages before deciding to migrate.
  • Optimise Gatsby first when the problem is specific and the platform is otherwise healthy.
  • Treat CMS sourcing, images, GraphQL queries, and page creation as separate costs.
  • Preview and editorial friction can matter as much as CI duration.
  • Migrate to Next.js when the build problem is part of a wider platform constraint.

Planning a platform change?

I help teams make difficult platform work clearer, from architecture decisions and migrations to launch recovery, performance, and search visibility.