Overview
The Citizen skin includes Progressive Web App (PWA) support through Service Worker integration. This allows users to install your wiki as a native application on their devices, providing app-like experiences including offline access (when implemented).PWA support is currently in early stages. The Service Worker is registered but does not yet implement caching or offline functionality.
What is a PWA?
A Progressive Web App is a web application that uses modern web capabilities to deliver app-like experiences:- Installable - Add to home screen on mobile/desktop
- App-like interface - Runs in standalone window
- Offline capable - Can work without network connection (requires implementation)
- Fast loading - Leverages caching strategies
- Auto-updates - Updates automatically when changes are published
Requirements
For PWA functionality to work, your MediaWiki installation must meet these requirements:1. Script Path at Root
Critical: The Service Worker only registers when$wgScriptPath is empty (root level).
Service-Worker-Allowed HTTP header requires web server configuration.
If your wiki is installed in a subdirectory (e.g.,
/wiki/), PWA features will not be available.2. HTTPS Required
Service Workers only work over HTTPS (except localhost for development):3. Browser Support
Browser must support Service Workers:- Chrome/Edge 40+
- Firefox 44+
- Safari 11.1+
- Opera 27+
How It Works
Service Worker Registration
The Citizen skin automatically registers a Service Worker when conditions are met:- Script path check - Verifies
$wgScriptPathis empty - Feature detection - Checks for Service Worker support
- Version tracking - Uses ResourceLoader module version for cache busting
- Scope - Registers at root scope (
/)
Service Worker Lifecycle
Once registered, the Service Worker goes through a lifecycle:- Install - Service Worker downloads and installs
- Activate - Service Worker activates and takes control
- Fetch - Service Worker intercepts network requests
Current Implementation Status
✓ Implemented
- Service Worker registration
- Lifecycle event listeners (install, activate, fetch)
- Scope and version management
- Script path validation
⏳ Planned Features
- Offline caching - Cache pages and resources for offline access
- Background sync - Queue edits when offline, sync when online
- Push notifications - Notify users of wiki updates
- Precaching - Cache essential pages on install
- Dynamic caching - Cache pages as users visit them
The Service Worker is registered but currently does not implement any caching or offline functionality. It serves as a foundation for future PWA features.
Configuration
Server Configuration
Script Path
Ensure MediaWiki is configured at root:HTTPS Setup
Configure your web server for HTTPS. Example for Apache:ResourceLoader Module
The Service Worker is defined inskin.json:
Testing PWA Installation
Chrome/Edge
- Visit your wiki over HTTPS
- Open DevTools → Application → Service Workers
- Verify Service Worker is registered
- Check for “Install” button in address bar
- Click to install as app
Mobile Devices
- Visit wiki in mobile browser
- Look for “Add to Home Screen” option
- Install the app
- App icon appears on home screen
- Launch opens in standalone mode
Future Development
Caching Strategies
Potential caching strategies for implementation:Cache First
Serve cached content first, fall back to network:Network First
Try network first, fall back to cache:Offline Page
Provide a custom offline page when network is unavailable:Best Practices
Be mindful of storage limits. Modern browsers typically allow 50MB+ per origin, but this varies by browser and device.
Troubleshooting
Service Worker Not Registering
Problem: Service Worker doesn’t registerSolutions:
- Verify
$wgScriptPathis empty - Check that site uses HTTPS
- Confirm browser supports Service Workers
- Check browser console for errors
Installation Option Not Appearing
Problem: No “Install App” optionSolutions:
- Ensure Service Worker is registered
- Verify site meets PWA criteria
- Check for manifest.json (if implemented)
- Test in different browser
Service Worker Not Updating
Problem: Changes to Service Worker not applyingSolutions:
- Hard refresh browser (Ctrl+Shift+R)
- Unregister old Service Worker in DevTools
- Clear site data
- Check ResourceLoader version is incrementing
Development Resources
Chrome DevTools
Application → Service Workers- View registration status
- Manually update Service Worker
- Unregister Service Workers
- Simulate offline mode
- Inspect cached resources
- Delete cache entries
- View cache size
Testing Checklist
- Service Worker registers successfully
- HTTPS is configured
- Script path is at root
- Browser supports Service Workers
- No console errors
- Version tracking works correctly
Contributing
The PWA implementation is in early stages and welcomes contributions:- Implement caching - Add smart caching strategies
- Offline support - Create offline fallback pages
- Background sync - Queue actions when offline
- Push notifications - Notify users of updates
- Manifest - Add web app manifest for better PWA support
resources/skins.citizen.scripts/serviceWorker.js- Registration logicresources/skins.citizen.serviceWorker/sw.js- Service Worker code
Refer to the MobileFrontend extension implementation for reference on MediaWiki Service Worker patterns.