---
title: "Edge functions, redirects and caching on Launch"
url: "https://developers.contentstack.com/guides/launch-edge-functions-redirects-and-caching"
type: "guide"
level: "intermediate"
intent: "build"
outcome: "You can route, transform, cache and debug requests on Launch with launch.json, an edge function, cache headers and the Revalidate CDN Cache API."
prerequisites:
  - "A site deployed on Contentstack Launch, or one you are about to deploy"
  - "Basic knowledge of HTTP status codes and Cache-Control headers"
  - "Familiarity with JavaScript and the Fetch API Request and Response objects"
next:
  - "https://developers.contentstack.com/guides/launch-edge-functions-redirects-and-caching/routing-with-launch-json"
tags:
  - "headless"
  - "api"
  - "next"
authors:
  - "Tim Benniks"
published: "2026-11-24T09:00:00.000Z"
updated: "2026-11-15T10:56:03.694Z"
---

# Edge functions, redirects and caching on Launch

- **Authors:** Tim Benniks
- **Published:** 2026-11-24T09:00:00.000Z
- **Updated:** 2026-11-15T10:56:03.694Z
- **Level:** Intermediate
- **Intent:** Build
- **Tags:** headless, api, next

---

> **Full guide available:** [View all 4 chapters in one document](https://developers.contentstack.com/guides/launch-edge-functions-redirects-and-caching/full.md)

Every request to a Launch site passes through a few layers before your framework sees it. Most of the hard production problems live in those layers: a redirect that loops, a page that stays stale after a publish, a personalized response that leaks to the wrong visitor, or an edge function that throws CFL-0001 and only tells you so in a log you didn't know existed.

This guide walks through those layers in the order Launch runs them. It assumes you have a site on Launch already. The examples use Next.js where a framework matters, but the platform features work the same for Nuxt, Astro, Angular or a static site.

## What you'll learn

- How to write redirects and rewrites in launch.json


- When an edge function is the right tool, and how to write one for geo, auth and A/B routing


- How the Launch CDN caches responses and how to refresh it on publish


- How to read edge and server logs, forward them with Log Targets, and stay inside platform limits



## How a request moves through Launch

Launch concept: Launch puts a CDN and an edge runtime in front of your origin. You configure the first part declaratively, the second part with JavaScript, and the cache with standard HTTP headers.

flowchart LR  A[Visitor] --> B[launch.json redirects and rewrites]  B --> C["Edge function (functions/[proxy].edge.js)"]  C --> D[CDN cache]  D -->|miss| E[Origin: SSR or Cloud Functions]  D -->|hit| AA few rules follow from that order:

- A matching redirect in launch.json wins. If you define the same redirect in launch.json and in your edge function, the launch.json one runs.


- Password protection also takes precedence over the edge function.


- The edge function runs before the cache, so it can change the URL that gets cached. That is what makes it useful for A/B routing and for stripping tracking parameters.


- A request that a rewrite or an edge function forwards to the origin does not invoke the edge function a second time.



If you are coming from Vercel or Netlify, think of launch.json as the redirects and headers section of vercel.json or netlify.toml, and the edge function as a single middleware that runs on every request.

## How the chapters fit together

Each chapter covers one layer and can be read on its own.

- [Routing with launch.json](/guides/launch-edge-functions-redirects-and-caching/routing-with-launch-json) covers redirects, rewrites, path patterns, header injection and the limits of the file.


- [Edge functions in practice](/guides/launch-edge-functions-redirects-and-caching/edge-functions-in-practice) covers the handler, environment variables, geolocation headers, header-based access control and cookie-based A/B routing.


- [Caching, revalidation and cache priming](/guides/launch-edge-functions-redirects-and-caching/caching-revalidation-and-cache-priming) covers Cache-Control, cache tags, the Revalidate CDN Cache API, revalidating on publish and warming the cache after a deployment.


- [Logs, debugging and limits](/guides/launch-edge-functions-redirects-and-caching/logs-debugging-and-limits) covers server logs, Log Targets, the numbers you need to remember and the mistakes that show up most often.



If you only need to pick between revalidating, priming and redeploying, read [Revalidate, prime or redeploy?](/blog/revalidate-prime-or-redeploy-picking-the-right-cache-lever-on-launch) first. If you want to drive deployments from a pipeline, continue with [Deploy from CI with the Launch CLI, REST API and deploy hooks](/guides/deploy-from-ci-with-the-launch-cli-and-api).

## Key takeaways

- Put static and pattern-based redirects and rewrites in launch.json at the root of your repository.


- Reach for functions/[proxy].edge.js only when the routing decision depends on request data such as headers, cookies or location.


- Treat Cache-Control as the contract with the CDN, and refresh it with the Revalidate CDN Cache API instead of redeploying for every content change.


- Check Server Logs first when something breaks at the edge, and set up a Log Target before you need history older than 24 hours.





---

## Do this with AI

Install the launch-platform skill from [Contentstack agent skills](https://github.com/contentstack/contentstack-agent-skills). Then ask your agent:

> Read my launch.json and functions folder and explain, for a request to /blog/old-post, which redirect, rewrite or edge function runs first and which cache headers the response ends up with.

New to this? [Set up your AI workbench](/guides/set-up-your-ai-workbench-for-contentstack) first.




---

## Frequently asked questions

### In what order does Launch process a request?

Redirects and rewrites from launch.json run first, then your edge function, then the CDN cache, and finally your origin (SSR or Cloud Functions).

### Do I need an edge function for redirects?

No. Static and pattern-based redirects belong in launch.json. Use an edge function when the decision depends on headers, cookies, geolocation or the hostname.

### Does Launch support Next.js revalidatePath and revalidateTag?

Not with the App Router Data Cache. On Launch you control caching with Cache-Control headers and refresh the CDN with the Revalidate CDN Cache API, Automations or a redeploy.

### Where do I see console.log output from an edge function?

In the Server Logs of the environment in Launch, with the CLI using csdx launch:logs, or in your own tooling through a Log Target.

