Menu
Important
Stay updated on React2Shell

Gatsby on Vercel

Last updated November 19, 2025

Gatsby is an open-source static-site generator. It enables developers to build fast and secure websites that integrate different content, APIs, and services.

Gatsby also has a large ecosystem of plugins and tools that improve the development experience. Vercel supports many Gatsby features, including Server-Side Rendering, Deferred Static Generation, API Routes, and more.

To get started with Gatsby on Vercel:

  • If you already have a project with Gatsby, install Vercel CLI and run the vercel command from your project's root directory
  • Clone one of our Gatsby example repos to your favorite git provider and deploy it on Vercel with the button below:

Vercel deployments can integrate with your git provider to generate preview URLs for each pull request you make to your Gatsby project.

Gatsby v4+ sites deployed to Vercel will automatically detect Gatsby usage and install the plugin.

To deploy your Gatsby site to Vercel, do not install the plugin yourself, or add it to your file.

Gatsby v5 sites require Node.js 20 or higher.

Vercel persists your Gatsby project's directory across builds.

Server-Side Rendering (SSR) allows you to render pages dynamically on the server. This is useful for pages where the rendered data needs to be unique on every request. For example, verifying authentication or checking the geolocation of an incoming request.

Vercel offers SSR that scales down resource consumption when traffic is low, and scales up with traffic surges. This protects your site from accruing costs during periods of no traffic or losing business during high-traffic periods.

You can server-render pages in your Gatsby application on Vercel using Gatsby's native Server-Side Rendering API. These pages will be deployed to Vercel as Vercel functions.

To server-render a Gatsby page, you must export an function called . The function can return an object with several optional keys, as listed in the Gatsby docs. The key will be available in your page's props in the property.

The following example demonstrates a server-rendered Gatsby page using :

To summarize, SSR with Gatsby on Vercel:

  • Scales to zero when not in use
  • Scales automatically with traffic increases
  • Has zero-configuration support for headers, including
  • Framework-aware infrastructure enables switching rendering between Edge/Node.js runtimes

Learn more about SSR

Deferred Static Generation (DSG) allows you to defer the generation of static pages until they are requested for the first time.

To use DSG, you must set the option to in the function in your file.

See the Gatsby docs on DSG to learn more.

To summarize, DSG with Gatsby on Vercel:

  • Allows you to defer non-critical page generation to user request, speeding up build times
  • Works out of the box when you deploy on Vercel
  • Can yield dramatic speed increases for large sites with content that is infrequently visited

Learn more about DSG

Gatsby supports Deferred Static Generation.

The static rendered fallback pages are not generated at build time. This differentiates it from incremental static regeneration (ISR). Instead, a Vercel Function gets invoked upon page request. And the resulting response gets cached for 10 minutes. This is hard-coded and currently not configurable.

See the documentation for Deferred Static Generation.

You can add API Routes to your Gatsby site using the framework's native support for the directory. Doing so will deploy your routes as Vercel functions. These Vercel functions can be used to fetch data from external sources, or to add custom endpoints to your application.

The following example demonstrates a basic API Route using Vercel functions:

To view your route locally, run the following command in your terminal:

Then navigate to in your web browser.

Vercel does not currently have first-class support for dynamic API routes in Gatsby. For now, using them requires the workaround described in this section.

To use Gatsby's Dynamic API routes on Vercel, you must:

  1. Define your dynamic routes in a file at the root directory of your project, as shown below:

  2. Read your dynamic parameters from , as shown below:

Although typically you'd access the dynamic parameter with when using Gatsby, you must use on Vercel.

Splat API routes are dynamic wildcard routes that will match anything after the splat (). Vercel does not currently have first-class support for splat API routes in Gatsby. For now, using them requires the workaround described in this section.

To use Gatsby's splat API routes on Vercel, you must:

  1. Define your splat routes in a file at the root directory of your project, as shown below:

  2. Read your dynamic parameters from , as shown below:

To summarize, API Routes with Gatsby on Vercel:

  • Scale to zero when not in use
  • Scale automatically with traffic increases
  • Can be tested as Vercel Functions in your local environment

Learn more about Gatsby API Routes

Gatsby does not have native framework support for using Routing Middleware.

However, you can still use Routing Middleware with your Gatsby site by creating a or file in your project's root directory.

The following example demonstrates middleware that adds security headers to responses sent to users who visit the route in your Gatsby application:

To summarize, Routing Middleware with Gatsby on Vercel:

  • Executes before a request is processed on a site, allowing you to modify responses to user requests
  • Runs on all requests, but can be scoped to specific paths through a config
  • Uses our lightweight Edge Runtime to keep costs low and responses fast

Learn more about Routing Middleware

Core Web Vitals are supported for Gatsby v4+ projects with no initial configuration necessary.

When you deploy a Gatsby v4+ site on Vercel, we automatically install the package and add it to the array in your file.

We do not recommend installing the Gatsby analytics plugin yourself.

To access your Core Web Vitals data, you must enable Vercel analytics in your project's dashboard. See our quickstart guide to do so now.

To summarize, using Speed Insights with Gatsby on Vercel:

Learn more about Speed Insights

While Gatsby does provide an Image plugin, it is not currently compatible with Vercel Image Optimization.

If this is something your team is interested in, please contact our sales team.

Learn more about Image Optimization

See our Frameworks documentation page to learn about the benefits available to all frameworks when you deploy on Vercel.


Was this helpful?

supported.