Subdomains / Wildcards
How to setup worker in one file for multiple subdomains
🛠️ Configuring a Single Service Worker for Multiple Projects
This guide explains how to configure one sw.js
file to support multiple PushPushGo projects using subdomain-based mapping. This is useful when you want to serve different push notification configurations for various portals under the same root domain (e.g., *.example.com
) without generating a separate worker file for each project.
📦 Use Case
You're managing several web portals like:
aaa.example.com
bbb.example.com
Each of these should receive push notifications from a separate PushPushGo project.
🧠 Solution
Instead of dynamically generating sw.js
for each subdomain, you can configure the service worker once and let it dynamically import the correct PushPushGo worker script based on the current hostname.
📄 Example sw.js
Implementation
sw.js
Implementation🔒 Notes
The service worker is cached by browsers for up to 24 hours, and it is re-fetched when:
The user first visits the site,
A push notification is delivered,
Or the browser refreshes the worker during its update cycle.
This solution ensures separation of concerns without server-side logic or full app bootstrapping.
If you manage a large number of subdomains, consider fetching the mapping from a remote JSON endpoint instead of hardcoding it.
🔪 Debugging Tips
Use browser DevTools → Application → Service Workers to inspect the registration and activity of the worker.
Make sure the worker is served with proper
Content-Type: application/javascript
and over HTTPS.
✅ Advantages
✅ Single worker script for all portals
✅ No dynamic server-side rendering needed
✅ Scalable and cache-efficient
✅ Supports clean and secure push notification routing
📞 Need Help?
For support or integration questions, contact the PushPushGo team or your technical lead.
Last updated
Was this helpful?