Varnish Logo

Overrides

Rules based on path or file-type to apply different behaviors to different parts of your site.

Targeted control for your content

By default, your service settings apply to every request. Overrides allow you to create exceptions to these global rules. Using path-based or file-type based matching, you can customize how Varnish CDN handles specific parts of your site.

For example, you might want your static images to stay in the cache for a month, while your API responses should only be cached for a few seconds.

How Overrides work

Each override consists of a Match (where the rule applies) and a Behavior (what the rule does).

1. Matching Logic

You can define which requests are affected by an override using two primary methods:

  • Path-based: Targets specific directories or URL patterns (e.g., /assets/* or /blog/posts/).
  • File-type based: Targets specific extensions regardless of their location (e.g., *.jpg, *.pdf, or *.js).

2. Overriding Behaviors

Once a match is found, you can "flick the switch" on specific settings for that traffic only. Some common use cases include:

  • Static & Dynamic Content: Cache static images long-term while keeping dynamic content fresh and up to date.
  • API Passthrough: Ensure dynamic data under /api/v1/* always fetches the latest version from the origin.
  • Security: Enforce higher security features for sensitive areas such as admin consoles.
  • Login: Prevent sensitive user session data from being stored at the edge.

Rule Precedence

Overrides are evaluated in the order they appear. If a request matches multiple overrides, the last matching rule typically takes precedence. You can reorder your rules in the dashboard to ensure the correct logic is applied.