Menu
Important
Stay updated on React2Shell

Astro on Vercel

Last updated September 24, 2025

Astro is an all-in-one web framework that enables you to build performant static websites. People choose Astro when they want to build content-rich experiences with as little JavaScript as possible.

You can deploy a static Astro app to Vercel with zero configuration.

To get started with Astro on Vercel:

  • If you already have a project with Astro, install Vercel CLI and run the vercel command from your project's root directory
  • Clone one of our Astro 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 Astro project.

To deploy a server-rendered Astro app, or a static Astro site with Vercel features like Web Analytics and Image Optimization, you must:

  1. Add Astro's Vercel adapter to your project. There are two ways to do so:

    • Using , which configures the adapter for you with default settings. Using will generate a preconfigured astro.config.ts with opinionated default settings
    • Or, manually installing the package. You should manually install the adapter if you don't want an opinionated initial configuration
  2. Configure your project. In your astro.config.ts file, import either the or plugin, and set the output to or respectively:

  3. Enable Vercel's features using Astro's configuration options. The following example astro.config.ts enables Web Analytics and adds a maximum duration to Vercel Function routes:

The following configuration options enable Vercel's features for Astro deployments.

OptiontypeRenderingPurpose
ServerlessExtends or limits the maximum duration (in seconds) that Vercel functions can run before timing out.
Static, ServerlessEnables Vercel's Web Analytics. See the quickstart to set up analytics on your account.
Static, ServerlessFor astro versions and up. Enables an automatically configured service to optimize your images.
Static, ServerlessFor astro versions and up. Configure the image service used to optimize your images in your dev environment.
Static, ServerlessDefines the behavior of the Image Optimization API, allowing on-demand optimization at runtime. See the Build Output API docs for required options.
ServerlessAPI routes are bundled into one function by default. Set this to true to split each route into separate functions.
ServerlessSet to to automatically convert Astro middleware to Routing Middleware, eliminating the need for a middleware.ts file.
ServerlessForce files to be bundled with your Vercel functions.
ServerlessExclude files from being bundled with your Vercel functions. Also available with

For more details on the configuration options, see Astro's docs.

Using SSR, or on-demand rendering as Astro calls it, enables you to deploy your routes as Vercel functions on Vercel. This allows you to add dynamic elements to your app, such as user logins and personalized content.

You can enable SSR by adding the Vercel adapter to your project.

If your Astro project is statically rendered, you can opt individual routes. To do so:

  1. Set your option to in your :

  2. Add to your components:

SSR with Astro on Vercel:

  • Scales to zero when not in use
  • Scales automatically with traffic increases
  • Has zero-configuration support for headers, including

Learn more about Astro SSR

Statically rendered, or pre-rendered, Astro apps can be deployed to Vercel with zero configuration. To enable Vercel features like Image Optimization or Web Analytics, see Using Vercel's features with Astro.

You can opt individual routes into static rendering with as shown below:

Statically rendered Astro sites on Vercel:

  • Require zero configuration to deploy
  • Can use Vercel features with astro.config.ts

Learn more about Astro Static Rendering

Incremental Static Regeneration (ISR) allows you to create or update content without redeploying your site. ISR has two main benefits for developers: better performance and faster build times.

To enable ISR in Astro, you need to use the Vercel adapter and set to in your configuration in :

ISR function requests do not include search params, similar to requests in static mode.

Using ISR with Astro on Vercel offers:

  • Better performance with our global CDN
  • Zero-downtime rollouts to previously statically generated pages
  • Global content updates in 300ms
  • Generated pages are both cached and persisted to durable storage

Learn more about ISR with Astro.

Vercel Functions use resources that scale up and down based on traffic demands. This makes them reliable during peak hours, but low cost during slow periods.

When you enable SSR with Astro's Vercel adapter, all of your routes will be server-rendered as Vercel functions by default. Astro's Server Endpoints are the best way to define API routes with Astro on Vercel.

When defining an Endpoint, you must name each function after the HTTP method it represents. The following example defines basic HTTP methods in a Server Endpoint:

Astro removes the final file during the build process, so the name of the file should include the extension of the data you want serve (for example example.png.js will become /example.png).

Vercel Functions with Astro on Vercel:

  • Scale to zero when not in use
  • Scale automatically as traffic increases

Learn more about Vercel Functions

Image Optimization helps you achieve faster page loads by reducing the size of images and using modern image formats. When deploying to Vercel, images are automatically optimized on demand, keeping your build times fast while improving your page load performance and Core Web Vitals.

Image Optimization with Astro on Vercel is supported out of the box with Astro's component. See the Image Optimization quickstart to learn more.

Image Optimization with Astro on Vercel:

  • Requires zero-configuration for Image Optimization when using Astro's component
  • Helps your team ensure great performance by default
  • Keeps your builds fast by optimizing images on-demand

Learn more about Image Optimization

Middleware is a function that execute before a request is processed on a site, enabling you to modify the response. Because it runs before the cache, Middleware is an effective way to personalize statically generated content.

Astro middleware allows you to set and share information across your endpoints and pages with a middleware.ts file in your directory. The following example edits the global object, adding data which will be available in any file:

Astro middleware is not the same as Vercel's Routing Middleware

, which has to be placed at the root directory of your project, outside src.

You can then access the data you added to in any file, like so:

You can deploy Astro's middleware at the Edge, giving you access to data in the and , and enabling you to use Vercel's Routing Middleware helpers, such as or .

To use Astro's middleware at the Edge, set in your astro.config.ts file:

If you're using Vercel's Routing Middleware, you do not need to set in your astro.config.ts file.

See Astro's docs on the limitations and constraints for using middleware at the Edge, as well as their troubleshooting tips.

The object exposes data to your components, allowing you to dynamically modify your content with middleware. To make changes to in Astro's middleware at the edge:

  1. Add a new middleware file next to your src/middleware.ts and name it src/vercel-edge-middleware.ts. This file name is required to make changes to . If you don't want to update , this step is not required

  2. Return an object with the properties you want to add to . :

Astro's middleware, which should be in src/middleware.ts, is distinct from Vercel Routing Middleware, which should be a middleware.ts file at the root of your project.

Vercel recommends using framework-native solutions. You should use Astro's middleware over Vercel's Routing Middleware wherever possible.

If you still want to use Vercel's Routing Middleware, see the Quickstart to learn how.

Rewrites only work for static files with Astro. You must use Vercel's Routing Middleware for rewrites. You should not use to rewrite URL paths with astro projects; doing so produces inconsistent behavior, and is not officially supported.

In general, Vercel recommends using framework-native solutions, and Astro has built-in support for redirects. That said, you can also do redirects with Vercel's Routing Middleware.

You can do redirects on Astro with astro.config.ts the config option as shown below:

You can also return a redirect from a Server Endpoint using the utility:

You can redirect from within Astro components with :

Astro Middleware 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 Vercel's lightweight Edge Runtime to keep costs low and responses fast

Learn more about Routing Middleware

Vercel automatically caches static files at the edge after the first request, and stores them for up to 31 days on Vercel's CDN. Dynamic content can also be cached, and both dynamic and static caching behavior can be configured with Cache-Control headers.

The following Astro component will show a new time every 10 seconds. It does by setting a 10 second max age on the contents of the page, then serving stale content while new content is being rendered on the server when that age is exceeded.

Learn more about Cache Control options.

You can also control how the cache behaves on any CDNs you may be using outside of Vercel's CDN with CDN Cache-Control Headers.

The following example tells downstream CDNs to cache the content for 60 seconds, and Vercel's CDN to cache it for 3600 seconds:

Learn more about CDN Cache-Control headers.

Caching on Vercel:

  • Automatically optimizes and caches assets for the best performance
  • Requires no additional services to procure or set up
  • Supports zero-downtime rollouts

Vercel Speed Insights provides you with a detailed view of your website's performance metrics, facilitating informed decisions for its optimization. By enabling Speed Insights, you gain access to the Speed Insights dashboard, which offers in-depth information about scores and individual metrics without the need for code modifications or leaving the dashboard.

To enable Speed Insights with Astro, see the Speed Insights quickstart.

To summarize, using Speed Insights with Astro on Vercel:

Learn more about Speed Insights

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

Learn more about deploying Astro projects on Vercel with the following resources:


Was this helpful?

supported.