Lesson 27 / 29

Deploying PWAs

Deploy your PWA to production with proper caching headers and version management.

Deployment considerations

Deploy on HTTPS always. Set cache headers: no-cache for HTML, long cache for versioned assets. Use service worker versioning and update checks. Configure CDN for fast delivery.

Cache header configuration (Nginx)

Proper cache headers for different file types in production.

# Cache static assets for 1 year
location ~* \.(js|css|png|jpg|svg)$ {
  expires 365d;
  add_header Cache-Control "public, immutable";
}

# Never cache HTML
location ~* \.html$ {
  expires -1;
  add_header Cache-Control "public, no-cache";
}

# Service worker - short cache
location = /sw.js {
  expires 1d;
  add_header Cache-Control "public, max-age=86400";
}

# Manifest - short cache
location = /manifest.json {
  expires 1h;
  add_header Cache-Control "public, max-age=3600";
}

Output:

Proper cache headers configured for PWA asset types.

A common trap

Never cache service worker files or manifest.json. Use short expiry times (1 hour) so updates are picked up quickly.