← Back to Tutorials Chapter 8

Serving Content

Hosting Your PWA

Your PWA can be hosted on any static file server. Popular options include:

HTTPS Configuration

Service Workers require HTTPS. Here's how to set it up on common platforms:

# Nginx HTTPS configuration
server {
    listen 443 ssl;
    server_name my-pwa.example.com;

    ssl_certificate /etc/letsencrypt/live/my-pwa/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/my-pwa/privkey.pem;

    root /var/www/my-pwa;
    index index.html;

    # Important: Serve Service Worker with correct headers
    location /sw.js {
        add_header Service-Worker-Allowed /;
        add_header Cache-Control "no-cache";
        add_header Content-Type "application/javascript";
    }

    # Cache static assets
    location /static/ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
}

CDN and Delivery

Content Delivery Networks (CDNs) can significantly improve load times for users around the world. When using a CDN with a PWA:

Security Considerations

# Security headers for PWA
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "DENY";
Exercise: Deploy your PWA to a free hosting service (Netlify, Vercel, or GitHub Pages). Verify that HTTPS is enabled, the Service Worker registers successfully, and the site works offline after the first visit.