ZephyrZephyr
Guide
Features
API
Examples
GitHub
Guide
Features
API
Examples
GitHub
  • Guide

    • Getting Started
    • Installation
    • Quick Start
    • Configuration

Configuration

Complete guide to configuring Zephyr.

Configuration Structure

const config = {
  // Caching rules (required)
  rules: [...],

  // Cache invalidation settings
  invalidation: {...},

  // Storage quota management
  quota: {...}
};

initZephyr(config);

Rules

Each rule defines what to cache and how:

{
  test: '.*\\.(png|jpg)$',   // Regex pattern to match URLs
  method: 'GET',              // HTTP method (optional)
  cache: 60,                  // TTL in minutes
  maxEntries: 100,            // Max entries for this rule
  timeout: 10000,             // Request timeout in ms
  fallback: {                 // Fallback strategy
    strategy: 'stale-if-error',
    maxStaleAge: 1440
  }
}

Rule Properties

PropertyTypeRequiredDefaultDescription
teststring✓-Regex pattern to match URLs
methodstring-allHTTP method to match
cachenumber✓-Cache TTL in minutes
maxEntriesnumber-100Max cached entries
timeoutnumber-10000Request timeout (ms)
fallbackobject--Fallback strategy

Invalidation

invalidation: {
  type: 'http',              // 'http', 'manifest', or 'header'
  respectHttpHeaders: true,  // Respect Cache-Control headers
  url: '/api/manifest.json', // For manifest type
  interval: 60000,           // Polling interval (ms)
  header: 'X-Cache-Version'  // For header type
}

See Cache Invalidation for details.

Quota

quota: {
  maxSize: 50 * 1024 * 1024,  // 50MB limit
  warningThreshold: 0.8,      // Warn at 80%
  onQuotaExceeded: 'evict-lru' // What to do when full
}

Quota Actions

ActionDescription
evict-lruRemove least recently used entries
stop-cachingStop caching new entries
clear-allClear entire cache

See Quota Management for details.

Complete Example

importScripts('https://unpkg.com/@maravilla-labs/zephyr@0.2.0/lib/zephyrWorker.js');

const config = {
  rules: [
    // Static assets - long cache
    {
      test: '.*\\.(png|jpg|jpeg|gif|webp|svg|ico)$',
      method: 'GET',
      cache: 1440,
      maxEntries: 200,
      fallback: {
        strategy: 'stale-if-error',
        maxStaleAge: 2880
      }
    },
    // API with background refresh
    {
      test: '.*\\/api\\/.*',
      method: 'GET',
      cache: 5,
      maxEntries: 100,
      fallback: {
        strategy: 'stale-while-revalidate'
      }
    },
    // Critical endpoints - always fresh
    {
      test: '.*\\/api\\/checkout',
      method: 'POST',
      cache: 1,
      fallback: {
        strategy: 'network-only'
      }
    }
  ],

  invalidation: {
    type: 'http',
    respectHttpHeaders: true
  },

  quota: {
    maxSize: 50 * 1024 * 1024,
    warningThreshold: 0.8,
    onQuotaExceeded: 'evict-lru'
  }
};

initZephyr(config);
Edit this page
Last Updated:: 1/13/26, 2:54 AM
Contributors: labertasch
Prev
Quick Start