---
title: "How to enable ETag support for static content (CSS, JS, images, etc.)"  
description: "How to enable ETag support for static content (CSS, JS, images, etc.)"  
author: "ICSM Computer"  
published: 2025-08-05  
updated: 2025-08-05  
canonical: https://www.mindstick.com/interview/34347/how-to-enable-etag-support-for-static-content-css-js-images-etc  
category: "cache"  
tags: ["cache"]  
reading_time: 4 minutes  

---

# How to enable ETag support for static content (CSS, JS, images, etc.)

## 1. ETag Support is Handled Automatically by IIS

For **static files**, IIS **automatically generates ETags** based on file metadata (like last modified date and file size).\
However, you can **control behavior and enhance caching** using `web.config`.

## 2. Enable/Disable ETags via IIS Settings

IIS adds headers like:

```plaintext
ETag: "6396c9a2b1d6d81:0"
Last-Modified: Wed, 06 Aug 2025 06:30:00 GMT
```

These are **enabled by default** unless removed via custom headers.

## 3. Control Cache for Static Content in `web.config`

You can’t directly configure ETag values in `web.config`, but you can combine ETag behavior with long-term caching:

### Example: Cache Static Files + Let IIS Handle ETag

```xml
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>
```

This will:

- Add `Cache-Control: public, max-age=...`
- Keep ETag behavior managed by IIS

## 4. Disable ETag (Optional)

If you want to **remove ETags** (for performance tuning or to rely only on `Cache-Control`):

### In `web.config`

```xml
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="ETag" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>
```

> ⚠️ This removes the `ETag` header from the response — not recommended unless you're managing cache manually.

## 5. Advanced (Optional): Use Versioned URLs Instead

Another best practice is to use **query string versioning** or **fingerprinted file names**:

```html
<!-- Better cache busting with versioned links -->
<link rel="stylesheet" href="/css/site.css?v=20250806" />
```

This makes the browser treat the URL as a "new" file if the version changes, avoiding reliance on ETag entirely.

## Summary

| **Goal** | **How** |
| --- | --- |
| Enable ETag for static files | IIS does this by default |
| Control cache duration | Use `<clientCache>` in `web.config` |
| Disable ETag | Remove `ETag` header via `customHeaders` |
| Version cache manually | Use versioned URLs (`?v=...`) in your markup |

## Answers

### Answer by ICSM Computer

## 1. ETag Support is Handled Automatically by IIS

For **static files**, IIS **automatically generates ETags** based on file metadata (like last modified date and file size).\
However, you can **control behavior and enhance caching** using `web.config`.

## 2. Enable/Disable ETags via IIS Settings

IIS adds headers like:

```plaintext
ETag: "6396c9a2b1d6d81:0"
Last-Modified: Wed, 06 Aug 2025 06:30:00 GMT
```

These are **enabled by default** unless removed via custom headers.

## 3. Control Cache for Static Content in `web.config`

You can’t directly configure ETag values in `web.config`, but you can combine ETag behavior with long-term caching:

### Example: Cache Static Files + Let IIS Handle ETag

```xml
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>
```

This will:

- Add `Cache-Control: public, max-age=...`
- Keep ETag behavior managed by IIS

## 4. Disable ETag (Optional)

If you want to **remove ETags** (for performance tuning or to rely only on `Cache-Control`):

### In `web.config`

```xml
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="ETag" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>
```

> ⚠️ This removes the `ETag` header from the response — not recommended unless you're managing cache manually.

## 5. Advanced (Optional): Use Versioned URLs Instead

Another best practice is to use **query string versioning** or **fingerprinted file names**:

```html
<!-- Better cache busting with versioned links -->
<link rel="stylesheet" href="/css/site.css?v=20250806" />
```

This makes the browser treat the URL as a "new" file if the version changes, avoiding reliance on ETag entirely.

## Summary

| **Goal** | **How** |
| --- | --- |
| Enable ETag for static files | IIS does this by default |
| Control cache duration | Use `<clientCache>` in `web.config` |
| Disable ETag | Remove `ETag` header via `customHeaders` |
| Version cache manually | Use versioned URLs (`?v=...`) in your markup |


---

Original Source: https://www.mindstick.com/interview/34347/how-to-enable-etag-support-for-static-content-css-js-images-etc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
