Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Vercel ~Vercel caches static and dynamic content~

How Vercel Caches Static and Dynamic Content An article based on the Vercel documentation page How requests flow through Vercel. Overview Most real-world applications serve a mix of static content (image

How Vercel Caches Static and Dynamic Content

An article based on the Vercel documentation page How requests flow through Vercel.

Overview

Most real-world applications serve a mix of static content (images, scripts, pre-rendered pages) and dynamic content (personalized or data-driven responses). Vercel handles both through a single request pipeline in which caching is one decision point among several. This article focuses on the caching stage, and places it in the context of the full journey a request takes.

Where caching fits in the request lifecycle

When a user hits enter in their browser, a request moves through these stages:

  1. Entering the network. DNS resolves the site to an anycast IP owned by Vercel. A global load balancer routes the request to the best of 100+ Points of Presence (PoPs), weighing network hops, round-trip time and available bandwidth. From there, traffic travels over a private fiber backbone rather than the public internet.
  2. Security. TLS is terminated, always-on system DDoS mitigation inspects traffic at layers 3, 4 and 7, and an optional Web Application Firewall (WAF) applies your custom rules.
  3. Routing (the proxy). An application-aware proxy consults globally replicated deployment metadata (derived from vercel.json or your framework config such as next.config.js) to decide:
    • whether the URL maps to a static file or a dynamic function,
    • whether a rewrite or redirect applies,
    • whether Routing Middleware (auth, A/B testing, etc.) must run first.
  4. Cache check. The proxy looks in the Vercel Cache for static assets, pre-rendered pages and other cacheable responses.
  5. Compute (if needed). Requests that can't be served from cache go to the compute layer.

The three cache outcomes

For any cacheable request, the Vercel Cache produces one of three results:

Status What happens
Hit The content is returned immediately from the Vercel region closest to the user.
Miss The content is generated in real time, and the result populates the cache for future requests.
Stale hit (ISR) Stale content is served instantly while fresh content is regenerated in the background.

Hit

The best case: no compute is needed, and the response comes from a nearby region, so latency is minimal.

Miss

The first request for an uncached resource has to be built on demand. Once built, the response is stored so later visitors get a hit.

Stale hit with ISR

With Incremental Static Regeneration (ISR), the cache serves the existing version to the current visitor right away and triggers regeneration in the background. The next visitor receives the refreshed content. This lets you update static content without rebuilding the whole site, and without making any user wait.

How dynamic content gets cached

Dynamic responses aren't excluded from caching. When a request needs personalization, fresh data or server-side logic, the proxy forwards it to the compute layer:

  1. The Vercel Functions router receives the request and manages concurrency. During large traffic spikes it queues and shapes traffic to prevent failures.
  2. A compute instance runs your code. With Fluid compute, an instance can handle multiple concurrent requests efficiently.
  3. In the response loop, the instance generates HTML or JSON and returns it through the proxy. If your response headers permit caching, the proxy stores the response so future requests can be served from cache instead of recomputing.

In other words, you control whether a dynamic response becomes reusable through the HTTP cache headers you set.

What feeds the cache: builds and deployments

The cache and compute layers rely on artifacts produced at deploy time. When you push code, Vercel:

  • detects your framework and runs your build command,
  • splits the output into static assets (sent to the cache) and compute artifacts (sent to the function store),
  • compiles your configuration into the metadata the proxy uses for routing decisions.

Practical takeaways

  • Prefer static or pre-rendered output where you can. Cache hits are the fastest and cheapest path.
  • Use ISR for content that changes occasionally. You get cached speed with periodic freshness, with no full rebuilds.
  • Set cache headers on dynamic responses that are safe to share. This lets the proxy reuse them instead of invoking compute each time.
  • Keep personalized responses uncacheable (or scoped appropriately), so one user's data is never served to another.
  • Use Routing Middleware sparingly on hot paths. It runs before the request completes, so it adds work to every matching request.

Further reading

Source

Vercel Docs, "How requests flow through Vercel": https://vercel.com/docs/fundamentals/infrastructure

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.