LogoLogo
Sign inSign up
  • PushPushGo Documentation
  • Web push
    • Overview
    • Instructions
      • Subscription tests
    • Service worker
      • Subdomains / Wildcards
    • Integration script
      • Subscription form
        • Subscription form creator
          • Topics
        • Subscription form delay
        • Display form rules
        • Confirmation window
      • Bell widget
        • Inbox
        • Topics
      • Google Analytics & Google Tag Manager
      • Default notification
      • Beacons
      • Security SRI / CSP
    • SDK Client
      • Legacy SDK (deprecated)
        • Examples
    • JS Code
    • Safari support
    • FAQ
  • Mobile push
    • Overview
    • Google Android
    • Apple iOS
    • Huawei Android
  • ONSITE NOTIFICATIONS
    • Overview
  • Onsite notifications
    • Create onsite notification
    • Edit onsite notification
    • Onsite notification report
    • Inbox
  • Onsite notifications list
  • Subscribers
    • Subscribers
      • Activity status
      • Subscriber Details
    • Labels
      • System Labels
      • Add Labels Manually
    • Segments
      • Create Segment
      • Copy Segment
      • Update Segment
      • Delete Segment
    • Geolocation
  • Campaigns
    • Campaigns
    • Push campaign
      • Create Campaign
        • Content
        • Audience
          • By Segment
          • By Labels
        • Provider options
        • Time
        • Drafts
      • Campaign List
        • Cancel Campaign
        • Copy Campaign
        • Copying and pasting campaigns between projects
        • Delete Campaign
      • Campaign Report
    • AB test
      • Create AB test
        • Variants
        • Audience
        • Provider options
        • Time
        • Save draft or accept a test
      • AB test list
      • Winner selection
      • AB test report
      • Cancel AB Test
      • Send AB test saved as draft
      • Resend AB test
      • Delete AB test
    • RSS campaign
      • Create RSS campaign
      • Audience
      • Enable RSS campaign
      • RSS campaign report
    • Chrome plugin for Rocket push
    • Multi Push
    • Daily push capping
    • Planner
    • FAQ
  • Automation
    • Overview
    • Automation
      • Create automation
        • Name
        • Flow
        • Renew flow
        • Start date
        • End date
        • Building the flow
        • Step
          • Trigger
          • Campaign
            • Create campaign
            • Edit campaign
            • Campaign templates
      • Edit automation
        • Update automation
      • Report
        • Automation report
        • Campaign report
    • Automation list
      • Prority
      • Action
      • Status
      • Reset flow time
  • Analytics
    • Project analytics
      • Subscribers
      • Campaigns
      • Automation
    • Organization analytics
      • Organization dashboard
        • Subscribers
        • Campaigns
        • Automation
      • Project comparison
    • Exports
  • Integrations
    • Webhooks
    • REST API Reference
  • Release notes
Powered by GitBook
On this page
  • 🛠️ Configuring a Single Service Worker for Multiple Projects
  • 📦 Use Case
  • 🧠 Solution
  • 📄 Example sw.js Implementation
  • 🔒 Notes
  • 🔪 Debugging Tips
  • ✅ Advantages
  • 📞 Need Help?

Was this helpful?

  1. Web push
  2. Service worker

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

// Map subdomains to PushPushGo project IDs
const idsMap = {
  'aaa.example.com': 'firstProjectId', // Replace with real ID
  'bbb.example.com': 'secondProjectId', // Replace with real ID
  // Add more domains as needed
};

let id = null;

// Determine the current subdomain
if (idsMap[self.location.hostname]) {
  id = idsMap[self.location.hostname];
}

if (id) {
  // Import the correct PushPushGo worker
  importScripts(`https://s-eu-1.pushpushgo.com/${id}/worker.js`);
} else {
  console.warn('[PushPushGo] No project ID configured for this domain:', self.location.hostname);
}

🔒 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 1 day ago

Was this helpful?