Progressive enhancement is a strategy for web design that emphasizes core web content first, then layers on more advanced features for browsers that support them. PWAs are the epitome of progressive enhancement.
Always check for feature support before using advanced APIs:
// Feature detection helper
function supports(feature) {
switch (feature) {
case 'service-worker':
return 'serviceWorker' in navigator;
case 'cache':
return 'caches' in window;
case 'indexeddb':
return 'indexedDB' in window;
case 'webgl':
return !!window.WebGLRenderingContext;
case 'webp':
const elem = document.createElement('canvas');
return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
case 'web-share':
return navigator.share !== undefined;
case 'clipboard':
return navigator.clipboard !== undefined;
case 'badging':
return navigator.setAppBadge !== undefined;
default:
return false;
}
}
// Usage
if (supports('web-share')) {
shareButton.style.display = 'block';
}
While progressive enhancement starts with the basics and adds features, graceful degradation starts with the full experience and scales back when features are missing.
// Graceful degradation example for push notifications
async function sendNotification(message) {
if (!('Notification' in window)) {
// Browser doesn't support notifications at all
showInlineAlert(message);
return;
}
if (Notification.permission === 'granted') {
new Notification(message);
return;
}
if (Notification.permission === 'default') {
const permission = await Notification.requestPermission();
if (permission === 'granted') {
new Notification(message);
} else {
showInlineAlert(message);
}
return;
}
// Permission denied
showInlineAlert(message);
}
Think of PWA features in layers:
| Layer | Features | Dependency |
|---|---|---|
| 1 - Core | Semantic HTML, CSS, content | None |
| 2 - Layout | Responsive design, Flexbox/Grid | Modern CSS |
| 3 - Interactivity | JavaScript, animations | JS enabled |
| 4 - Offline | Service Worker, Cache | HTTPS + modern browser |
| 5 - App-like | Manifest, install prompt | Layer 4 |
| 6 - Advanced | Push, sync, badges, share | Layer 4 + permissions |
Always test your PWA at each enhancement layer: