Course contentsShow
← Web Development
Lesson 2933 of 2,98252. Frontend SecurityFree lesson

Service Workers Require HTTPS

Understand why service workers, push notifications, and PWA features only work over HTTPS.

Service Workers Require HTTPS

What you'll learn: Why service workers, push notifications, and Progressive Web App features only function over secure HTTPS connections.

Modern browsers enforce a critical security rule: service workers only work on HTTPS origins (with a localhost exception for development). This isn't arbitrary—it's essential protection against a devastating class of attacks.

Why the HTTPS Requirement Exists

Service workers are incredibly powerful. They sit between your web page and the network, intercepting every request your site makes. This includes the ability to:

  • Modify or fabricate responses
  • Cache resources offline
  • Intercept API calls
  • Serve entirely different content

Imagine if an attacker on public Wi-Fi could inject a malicious service worker into your HTTP site. They could permanently compromise your application—even after the user leaves that network. The service worker would persist, intercepting passwords, payment details, and personal data indefinitely.

HTTPS prevents this by ensuring the service worker code is authentically from your server and hasn't been tampered with during transmission.

What This Means for PWA Features

Since Progressive Web App capabilities build on service workers, they inherit this requirement:

  • Push notifications require HTTPS
  • Background sync requires HTTPS
  • Offline functionality requires HTTPS
  • Add to home screen capabilities require HTTPS

The Localhost Exception

Browsers allow service workers on http://localhost or 127.0.0.1 for development purposes. This lets you test locally without SSL certificates. However, production deployments must use HTTPS—no exceptions.

This security measure ensures that when users interact with your PWA, they're protected from man-in-the-middle attacks that could hijack the powerful service worker layer.

Key Takeaway: Service workers' ability to intercept all network requests makes them a potential security risk over HTTP; HTTPS is mandatory (except localhost) to ensure the integrity and authenticity of service worker code.