---
title: Adding a response header
description: Learn how to add a response header in your Middleware.
url: "https://vercel.com/kb/guide/add-response-header"
published: 2025-11-03
last_updated: 2025-11-21
authors: DX Team
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---

The following example shows how to add a response header in your Middleware

Your `middleware` file should be placed at the root of your project. If you are using the `src` directory, the file should be placed in the `src` directory.

```javascript
import { NextResponse } from 'next/server';

export default function middleware() {
  // Store the response so we can modify its headers
  const response = NextResponse.next();

  // Set custom header
  response.headers.set('x-modified-edge', 'true');

  // Return response
  return response;
}
```
```typescript
import { NextResponse } from 'next/server';

export default function middleware() {
  // Store the response so we can modify its headers
  const response = NextResponse.next();

  // Set custom header
  response.headers.set('x-modified-edge', 'true');

  // Return response
  return response;
}
```
```javascript
import { NextResponse } from 'next/server';

export default function middleware() {
  // Store the response so we can modify its headers
  const response = NextResponse.next();

  // Set custom header
  response.headers.set('x-modified-edge', 'true');

  // Return response
  return response;
}
```
```typescript
import { NextResponse } from 'next/server';

export default function middleware() {
  // Store the response so we can modify its headers
  const response = NextResponse.next();

  // Set custom header
  response.headers.set('x-modified-edge', 'true');

  // Return response
  return response;
}
```
```javascript
import { next } from '@vercel/functions';

export default function middleware() {
  // Store the response so we can modify its headers
  const response = next();

  // Set custom header
  response.headers.set('x-modified-edge', 'true');

  // Return response
  return response;
}
```
```typescript
import { next } from '@vercel/functions';

export default function middleware() {
  // Store the response so we can modify its headers
  const response = next();

  // Set custom header
  response.headers.set('x-modified-edge', 'true');

  // Return response
  return response;
}
```

## More resources

- [Middleware](/docs/routing-middleware)
  
- [Middleware API](/docs/routing-middleware/api)
  
- [NextResponse API](https://nextjs.org/docs/app/api-reference/functions/next-response)

## More Next.js guides

- [How do I reduce my build time with Next.js on Vercel?](/kb/guide/how-do-i-reduce-my-build-time-with-next-js-on-vercel): Reduce Next.js build times on Vercel by pre-rendering fewer pages at build time, deferring generation with ISR and image optimization, and using faster build machines.
- [Integrating AWS Secrets Manager with Vercel Using Terraform](/kb/guide/integrating_aws_secrets_manager_with_vercel_using_terraform): Learn how to seamlessly integrate AWS Secrets Manager with Vercel for enhanced security and efficiency in your web deployments using Terraform with our comprehensive guide.
- [Can I redirect from a subdomain to a subpath?](/kb/guide/can-i-redirect-from-a-subdomain-to-a-subpath): Learn how to redirect from your subdomain to a subpath on Vercel with a vercel.json file or with Next.js