---
title: "Static files in Varnish"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how Acquia's Varnish handles static file caching, cookie stripping, excluded file types, and custom cache policies for your Cloud Platform site."
image:
type: "page"
url: "/acquia-cloud-platform/static-files-varnish"
id: "02030a31-1e1b-412c-a582-44ccd0196435"
---

Acquia's Varnish® configuration enforces policies for static files served from applications on Cloud Platform. In certain circumstances, these configurations can be modified by changing your website's `.htaccess` file.

Stripping cookies from static files
-----------------------------------

Since cookies can cause your cache to vary, files of the following types managed by Drupal in the `modules`, `themes`, `files`, or `libraries` directories have incoming cookie headers removed, and receive the HTTP request header `X-Static-Asset: True`:

*   Text: `htm`, `html`, `css`, `js`, `json`, `yml`, `xml`, `txt`
*   Images: `gif`, `png`, `jpg`, `jpeg`, `pdf`, `svg`, `ico`, `webp`
*   Media: `ogg`, `ogv`, `webm`, `mp3`, `mp4`, `mov`, `f4v`
*   Publishing: `doc`, `ttf`, `eot`, `ppt`, `xls`, `otf`, `woff`, `woff2`
*   Archives: `tbz`, `bz2`, `rar`

Important

Caching `.mjs` files in Varnish

Cloud Platform static-asset list does not include `.mjs` (ES module JavaScript) files. Unlike `.js` files, `.mjs` files do not receive cookie stripping or the `X-Static-Asset: True` header from Varnish.

To cache `.mjs` files through Varnish or set cache headers for them, add an explicit `<FilesMatch>` rule to the `.htaccess` file:

    <FilesMatch "\.(js|mjs)$">
      Header set Cache-Control "max-age=604800, public"
    </FilesMatch>

To use `<FilesMatch>` with `.htaccess` on Cloud Platform, refer to [Set max-age headers for specific pages, files, or paths](/acquia-cloud-platform/help/92841-set-max-age-headers-specific-pages-files-or-paths).

Any file type smaller than 10MB in size not included in the [Common file types excluded from Varnish caching](#varnish-excluded-types) list can have its `Cache-Control` headers modified in your website's `.htaccess` file to make the file type cacheable or uncacheable.

Common file types excluded from Varnish caching
-----------------------------------------------

The following file types (which are generally large in size) are always excluded from Varnish caching:

*   `dmg`
*   `exe`
*   `gz`
*   `msi`
*   `pkg`
*   `tgz`
*   `zip`

You should use a content delivery network (CDN), such as [Edge](/acquia-cloud-platform/add-ons/edge), or another [external storage system](/acquia-cloud-platform/help/93236-handling-large-files "Handling large files") for serving larger assets of these types.

Files greater than 10 MB in size
--------------------------------

HTTP responses with a `Content-Length` header larger than 10MB (10,000,000 bytes) in size cannot be cached, but will instead be streamed.

To preserve website uptime and availability, either use a content delivery network (such as [Edge](/acquia-cloud-platform/add-ons/edge)) or another [external storage system](/acquia-cloud-platform/help/93236-handling-large-files "Handling large files") for serving large assets.

Creating custom caching policy per file type
--------------------------------------------

If you want to set a specific cache policy for certain file types, you can add lines to your `.htaccess` file to set a custom `Cache-Control` HTTP header per file type, based on the following example:

    # Exclude files of the following types from Varnish caching
    <FilesMatch "\.(iso|bmp|psd|flac|avi|mpeg)$">
      Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
    </FilesMatch>

Note

As an alternative to `mod_headers`, use the `mod_expires` Apache module to set cache lifetimes. Refer to [Set max-age headers for specific pages, files, or paths](/acquia-cloud-platform/help/92841-set-max-age-headers-specific-pages-files-or-paths). for a comparison between `mod_expires` and `mod_headers` and to access usage examples.

Using the Purge file module
---------------------------

Through [Purge file](https://www.drupal.org/project/purge_file) module, you can efficiently manage and clear static file caches, improve your content update workflows, and reduce dependency on manual cache clearing. This module ensures that the system does not serve outdated static files and instead serves updated versions through communication with Varnish and other caching layers. This module works only on files that are [managed by Drupal](https://www.drupal.org/docs/8/core/modules/file/overview "https://www.drupal.org/docs/8/core/modules/file/overview") and does not handle files uploaded by SFTP or some other way.