Edge Rules make it easy to customize cache times based on file extensions. This is useful when different content types need different caching strategies—for example, caching video files longer than HTML pages.
Use cases
- Cache static assets (images, CSS, JS) for longer periods
- Set shorter cache times for dynamic content
- Cache video files for extended periods to reduce origin load
- Override default cache behavior for specific file types
Configuration
Open Edge Rules
Navigate to your pull zone and select Edge Rules from the side menu.
Add a new rule
Click Add Edge Rule to create a new rule.
Select the Override Cache Time action
Choose Override Cache Time as the action.Enter the desired cache time in seconds:| Duration | Seconds |
|---|
| 1 hour | 3600 |
| 1 day | 86400 |
| 1 week | 604800 |
| 1 month | 2592000 |
Add a File Extension condition
Click Add Condition and select File Extension as the condition type.Enter the extension you want to match (without the dot). For example:
mp4 for video files
jpg for JPEG images
css for stylesheets
Save the rule
Click Save Edge Rule to activate.
Examples
Cache video files for 30 days
| Setting | Value |
|---|
| Action | Override Cache Time |
| Cache Time | 2592000 (30 days) |
| Condition | File Extension |
| Extension | mp4 |
Cache images for 1 week
| Setting | Value |
|---|
| Action | Override Cache Time |
| Cache Time | 604800 (7 days) |
| Condition | File Extension |
| Extension | jpg |
Create separate rules for each file extension, or use multiple conditions with
Match Any to apply the same cache time to multiple extensions.
Bypass cache for HTML files
To prevent caching of HTML files entirely:
| Setting | Value |
|---|
| Action | Override Cache Time |
| Cache Time | 0 |
| Condition | File Extension |
| Extension | html |
Setting cache time to 0 will bypass the edge cache if the content is not
already cached. This increases origin load but ensures fresh content.
Multiple extensions
To apply the same cache time to multiple file types, you have two options:
Option 1: Multiple conditions (Match Any)
Add multiple File Extension conditions to a single rule and set the match type to Match Any:
- Condition 1: File Extension =
jpg
- Condition 2: File Extension =
png
- Condition 3: File Extension =
gif
Option 2: Separate rules
Create individual rules for each extension. This gives you more flexibility if you later need different cache times per extension.
Cache time vs Browser cache time
Edge Rules offer two cache-related actions:
| Action | Description |
|---|
| Override Cache Time | Controls how long content is cached on bunny.net edge servers |
| Override Browser Cache Time | Controls the Cache-Control header sent to browsers |
You can use both together to have different cache durations at the edge vs in the browser.