{"id":3603,"date":"2026-11-28T10:06:27","date_gmt":"2026-11-28T04:36:27","guid":{"rendered":"https:\/\/larapush.com\/blog\/?p=3603"},"modified":"2026-11-28T10:06:27","modified_gmt":"2026-11-28T04:36:27","slug":"web-push-with-existing-service-worker","status":"publish","type":"post","link":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/","title":{"rendered":"How Do You Add Web Push to an Existing Service Worker?"},"content":{"rendered":"\n<p><strong>To add web push to an existing service worker, put the push and notificationclick handlers into the worker you already register, or load a push script inside it with importScripts(). Don&#8217;t register a second service worker at the same scope, because only one can control a scope and the new one replaces your existing worker, breaking caching or push.<\/strong><\/p>\n\n\n\n<p>This is one of the most common setup problems I see on sites that already run a PWA, an offline cache or a Workbox build. A push tool asks you to upload its own service worker file, and suddenly the offline mode stops working, or push stops after the next deploy. Here&#8217;s how to combine web push with an existing service worker cleanly.<\/p>\n\n\n\n<p>Key facts at a glance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>One per scope:<\/strong> a scope, such as \/, has one active service worker. Registering a different file at the same scope swaps it in. See MDN on <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/ServiceWorkerContainer\/register\" target=\"_blank\" rel=\"noreferrer noopener\">ServiceWorkerContainer.register()<\/a>.<\/li>\n\n\n\n<li><strong>importScripts():<\/strong> a classic service worker can load extra scripts, which is the simplest way to add push code.<\/li>\n\n\n\n<li><strong>Workbox:<\/strong> the generateSW mode has an importScripts option, and injectManifest lets you write your own worker. See <a href=\"https:\/\/developer.chrome.com\/docs\/workbox\/modules\/workbox-build\" target=\"_blank\" rel=\"noreferrer noopener\">Workbox&#8217;s build docs<\/a>.<\/li>\n\n\n\n<li><strong>Firebase:<\/strong> getToken() accepts a serviceWorkerRegistration option, so FCM can use your existing worker. See <a href=\"https:\/\/firebase.google.com\/docs\/reference\/js\/messaging_.gettokenoptions\" target=\"_blank\" rel=\"noreferrer noopener\">Firebase&#8217;s GetTokenOptions reference<\/a>.<\/li>\n<\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#Why_cant_you_just_add_a_second_service_worker\" title=\"Why can&#8217;t you just add a second service worker?\">Why can&#8217;t you just add a second service worker?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#How_do_you_merge_push_code_into_your_service_worker\" title=\"How do you merge push code into your service worker?\">How do you merge push code into your service worker?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#How_do_you_load_a_vendors_push_script_with_importScripts\" title=\"How do you load a vendor&#8217;s push script with importScripts()?\">How do you load a vendor&#8217;s push script with importScripts()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#How_do_you_add_push_to_a_Workbox_service_worker\" title=\"How do you add push to a Workbox service worker?\">How do you add push to a Workbox service worker?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#generateSW\" title=\"generateSW\">generateSW<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#injectManifest\" title=\"injectManifest\">injectManifest<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#How_do_you_make_Firebase_use_your_existing_worker\" title=\"How do you make Firebase use your existing worker?\">How do you make Firebase use your existing worker?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#Will_existing_subscribers_break_when_you_merge_workers\" title=\"Will existing subscribers break when you merge workers?\">Will existing subscribers break when you merge workers?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#How_do_you_test_the_merged_worker\" title=\"How do you test the merged worker?\">How do you test the merged worker?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#Where_LaraPush_fits\" title=\"Where LaraPush fits\">Where LaraPush fits<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#Frequently_asked_questions\" title=\"Frequently asked questions\">Frequently asked questions<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_cant_you_just_add_a_second_service_worker\"><\/span>Why can&#8217;t you just add a second service worker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can&#8217;t add a second service worker at the same scope because the browser keeps one registration per scope. When you register a different script URL there, the browser treats it as an update and replaces the old worker.<\/p>\n\n\n\n<p>So if your PWA registers \/sw.js and a push tool registers \/push-sw.js, both at the root scope, they fight. Whichever registers last wins. The loser&#8217;s code, whether offline caching or the push handler, stops running.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Approach<\/th><th>Works?<\/th><th>Problem<\/th><\/tr><\/thead><tbody><tr><td>Two workers, same scope<\/td><td>No<\/td><td>The last one registered replaces the other<\/td><\/tr><tr><td>Two workers, different scopes<\/td><td>Partly<\/td><td>Push only works for pages in the push worker&#8217;s scope<\/td><\/tr><tr><td>One worker with all handlers<\/td><td>Yes<\/td><td>You maintain one file<\/td><\/tr><tr><td>One worker plus importScripts()<\/td><td>Yes<\/td><td>Cleanest when the push code comes from a vendor<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Different scopes can work in narrow cases. For example, Firebase&#8217;s default worker uses its own scope. But a push worker registered under a sub-path can&#8217;t control your main pages, so prompts and clicks get messy. One worker per site is easier to reason about.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_merge_push_code_into_your_service_worker\"><\/span>How do you merge push code into your service worker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Add a push listener and a notificationclick listener to the service worker you already have. Your fetch and cache logic stays exactly as it is, since each event type has its own listener.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ existing code stays: install, activate, fetch...\n\nself.addEventListener('push', (event) =&gt; {\n  const data = event.data ? event.data.json() : {};\n  event.waitUntil(\n    self.registration.showNotification(data.title || 'Update', {\n      body: data.body,\n      icon: data.icon,\n      data: { url: data.url || '\/' }\n    })\n  );\n});\n\nself.addEventListener('notificationclick', (event) =&gt; {\n  event.notification.close();\n  event.waitUntil(clients.openWindow(event.notification.data.url));\n});<\/code><\/pre>\n\n\n\n<p>Multiple listeners for the same event are allowed, but avoid two push handlers that both show a notification. You&#8217;d get duplicates. My guide to the <a href=\"https:\/\/larapush.com\/blog\/service-worker-for-web-push\/\">service worker for web push<\/a> explains each event in more depth.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_load_a_vendors_push_script_with_importScripts\"><\/span>How do you load a vendor&#8217;s push script with importScripts()?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If your push provider gives you a service worker file, load it from your own worker with importScripts() instead of registering it separately. The vendor&#8217;s handlers then run inside your single worker.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Keep your existing worker, such as \/sw.js, as the only registered file.<\/li>\n\n\n\n<li>Host the vendor&#8217;s push script on your own domain, for example \/push-handler.js.<\/li>\n\n\n\n<li>Add importScripts(&#8216;\/push-handler.js&#8217;); at the top of \/sw.js.<\/li>\n\n\n\n<li>Remove any separate navigator.serviceWorker.register() call for the vendor file.<\/li>\n\n\n\n<li>Deploy, then confirm in DevTools that one worker is active and both caching and push work.<\/li>\n<\/ol>\n\n\n\n<p>Note that importScripts() only works in classic service workers. If your worker is registered with type: &#8216;module&#8217;, use a normal import statement instead.<\/p>\n\n\n\n<p>Before you do this, ask your vendor whether they support it. Some tools expect their own file name at a fixed path. If you rename it, update their settings too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_add_push_to_a_Workbox_service_worker\"><\/span>How do you add push to a Workbox service worker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>With Workbox, use importScripts in generateSW mode or switch to injectManifest. Both keep Workbox&#8217;s precaching and add your push code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"generateSW\"><\/span>generateSW<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The generateSW mode builds the whole worker for you. Its importScripts option adds your push script to the generated file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ workbox-config.js\nmodule.exports = {\n  globDirectory: 'dist\/',\n  globPatterns: ['**\/*.{html,js,css}'],\n  swDest: 'dist\/sw.js',\n  importScripts: ['push-handler.js']\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"injectManifest\"><\/span>injectManifest<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The injectManifest mode lets you write your own worker, and Workbox only injects the precache list. Put your push and notificationclick listeners in that source file. I prefer this mode once a site has custom logic, because everything sits in one readable file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_make_Firebase_use_your_existing_worker\"><\/span>How do you make Firebase use your existing worker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Pass your own registration to getToken(). By default, the Firebase JS SDK looks for \/firebase-messaging-sw.js. However, you can give it the registration of the worker you already use.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const reg = await navigator.serviceWorker.register('\/sw.js');\nconst token = await getToken(messaging, {\n  vapidKey: 'YOUR_PUBLIC_VAPID_KEY',\n  serviceWorkerRegistration: reg\n});<\/code><\/pre>\n\n\n\n<p>Then add the Firebase messaging code, or your own push handler, inside \/sw.js. For the bigger picture of Firebase setup, see <a href=\"https:\/\/larapush.com\/blog\/connect-firebase-to-self-hosted-web-push\/\">how to connect Firebase to self-hosted web push<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Will_existing_subscribers_break_when_you_merge_workers\"><\/span>Will existing subscribers break when you merge workers?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>They can, if the merge changes the scope or the keys. A push subscription belongs to a service worker registration, so moving push to a different scope can leave old subscriptions without a handler.<\/p>\n\n\n\n<p>Keep these the same during a merge:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Scope:<\/strong> keep the registration that holds the subscriptions, usually at \/.<\/li>\n\n\n\n<li><strong>VAPID keys:<\/strong> keep the same application server key, or subscriptions must be recreated. See my guide to <a href=\"https:\/\/larapush.com\/blog\/vapid-keys-web-push\/\">VAPID keys<\/a>.<\/li>\n\n\n\n<li><strong>Origin:<\/strong> stay on the same domain.<\/li>\n<\/ul>\n\n\n\n<p>If you must change the file name or path, read <a href=\"https:\/\/larapush.com\/blog\/changing-service-worker-file-web-push\/\">what happens when you change the service worker file<\/a> first. Then test on a staging copy before release.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_test_the_merged_worker\"><\/span>How do you test the merged worker?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Test caching and push together, because a merge that fixes one can break the other. Chrome DevTools shows the active worker and lets you send a test push.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open DevTools, then Application, then Service Workers.<\/li>\n\n\n\n<li>Confirm one active worker at the expected scope, with the expected file name.<\/li>\n\n\n\n<li>Click Push to fire a test event and check that a notification appears.<\/li>\n\n\n\n<li>Go offline in the Network panel and reload to check that caching still works.<\/li>\n\n\n\n<li>Send a real message from your server or panel to a test device.<\/li>\n<\/ol>\n\n\n\n<p>My guide to <a href=\"https:\/\/larapush.com\/blog\/debug-web-push-in-chrome-devtools\/\">debugging web push in Chrome DevTools<\/a> covers these screens step by step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_LaraPush_fits\"><\/span>Where LaraPush fits<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaraPush is a self-hosted web push panel that you install on your own VPS, with a one-time licence from $499 (check <a href=\"https:\/\/larapush.com\/pricing\/\">LaraPush pricing<\/a>). Setup involves embedding its JavaScript and service worker on your site, or using the WordPress plugin. If your site already has a PWA or Workbox worker, read the <a href=\"https:\/\/larapush.com\/guide\/\">LaraPush guide<\/a> and ask support how its worker file should sit alongside yours before going live. The trade-offs are no free plan and a server you maintain. The <a href=\"https:\/\/larapush.com\/features\/\">features page<\/a> lists what the panel includes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_asked_questions\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1764322000000\"><strong class=\"schema-faq-question\">Can a website have two service workers?<\/strong> <p class=\"schema-faq-answer\">A site can have several registrations, but each scope has only one active service worker. Two workers at the same scope replace each other. Workers at different scopes can coexist, but each only controls pages inside its own path, which makes push and caching harder to manage.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764322001111\"><strong class=\"schema-faq-question\">Does adding push code slow down my service worker?<\/strong> <p class=\"schema-faq-answer\">Not noticeably. Push and notificationclick listeners only run when those events fire, so they don&#8217;t affect page loads or fetch handling. The main cost is the extra script download the first time the worker installs or updates.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764322002222\"><strong class=\"schema-faq-question\">Can I use importScripts() in a module service worker?<\/strong> <p class=\"schema-faq-answer\">No. importScripts() only works in classic service workers. If you register your worker with type module, use standard import statements to bring in the push code instead, and check that your target browsers support module service workers.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764322003333\"><strong class=\"schema-faq-question\">Why did push stop working after I installed a PWA plugin?<\/strong> <p class=\"schema-faq-answer\">The PWA plugin probably registered its own service worker at the root scope, replacing your push worker. Merge both into one file, or use the plugin&#8217;s option to import extra scripts, then confirm in DevTools that one worker handles both caching and push.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764322004444\"><strong class=\"schema-faq-question\">Do I need firebase-messaging-sw.js to use FCM on the web?<\/strong> <p class=\"schema-faq-answer\">No. That&#8217;s only the default file name the Firebase SDK looks for. Pass your own service worker registration to getToken() with the serviceWorkerRegistration option, and put the messaging or push handler code in your existing worker.<\/p> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"Add web push to an existing service worker, PWA or Workbox build without breaking caching: merge handlers, importScripts and Firebase setup.","protected":false},"author":7,"featured_media":3610,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":""},"categories":[68],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How Do You Add Web Push to an Existing Service Worker?<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Do You Add Web Push to an Existing Service Worker?\" \/>\n<meta property=\"og:description\" content=\"Add web push to an existing service worker, PWA or Workbox build without breaking caching: merge handlers, importScripts and Firebase setup.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\" \/>\n<meta property=\"og:site_name\" content=\"LaraPush Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-28T04:36:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ritesh Das\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ritesh Das\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\"},\"author\":{\"name\":\"Ritesh Das\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\"},\"headline\":\"How Do You Add Web Push to an Existing Service Worker?\",\"datePublished\":\"2026-11-28T04:36:27+00:00\",\"dateModified\":\"2026-11-28T04:36:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\"},\"wordCount\":1382,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg\",\"articleSection\":[\"How to\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\",\"url\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\",\"name\":\"How Do You Add Web Push to an Existing Service Worker?\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg\",\"datePublished\":\"2026-11-28T04:36:27+00:00\",\"dateModified\":\"2026-11-28T04:36:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322000000\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322001111\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322002222\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322003333\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322004444\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Illustration of web push added to an existing service worker, a gear cog connected to a cache, a bell and a puzzle piece\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/larapush.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Do You Add Web Push to an Existing Service Worker?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/larapush.com\/blog\/#website\",\"url\":\"https:\/\/larapush.com\/blog\/\",\"name\":\"LaraPush Blog\",\"description\":\"Stay Ahead, Stay Notified with LaraPush!\",\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/larapush.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/larapush.com\/blog\/#organization\",\"name\":\"LaraPush\",\"url\":\"https:\/\/larapush.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png\",\"width\":280,\"height\":60,\"caption\":\"LaraPush\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\",\"name\":\"Ritesh Das\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g\",\"caption\":\"Ritesh Das\"},\"url\":\"https:\/\/larapush.com\/blog\/author\/riteshdas\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322000000\",\"position\":1,\"url\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322000000\",\"name\":\"Can a website have two service workers?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"A site can have several registrations, but each scope has only one active service worker. Two workers at the same scope replace each other. Workers at different scopes can coexist, but each only controls pages inside its own path, which makes push and caching harder to manage.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322001111\",\"position\":2,\"url\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322001111\",\"name\":\"Does adding push code slow down my service worker?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Not noticeably. Push and notificationclick listeners only run when those events fire, so they don't affect page loads or fetch handling. The main cost is the extra script download the first time the worker installs or updates.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322002222\",\"position\":3,\"url\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322002222\",\"name\":\"Can I use importScripts() in a module service worker?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. importScripts() only works in classic service workers. If you register your worker with type module, use standard import statements to bring in the push code instead, and check that your target browsers support module service workers.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322003333\",\"position\":4,\"url\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322003333\",\"name\":\"Why did push stop working after I installed a PWA plugin?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The PWA plugin probably registered its own service worker at the root scope, replacing your push worker. Merge both into one file, or use the plugin's option to import extra scripts, then confirm in DevTools that one worker handles both caching and push.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322004444\",\"position\":5,\"url\":\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322004444\",\"name\":\"Do I need firebase-messaging-sw.js to use FCM on the web?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. That's only the default file name the Firebase SDK looks for. Pass your own service worker registration to getToken() with the serviceWorkerRegistration option, and put the messaging or push handler code in your existing worker.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Do You Add Web Push to an Existing Service Worker?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/","og_locale":"en_US","og_type":"article","og_title":"How Do You Add Web Push to an Existing Service Worker?","og_description":"Add web push to an existing service worker, PWA or Workbox build without breaking caching: merge handlers, importScripts and Firebase setup.","og_url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/","og_site_name":"LaraPush Blog","article_published_time":"2026-11-28T04:36:27+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg","type":"image\/jpeg"}],"author":"Ritesh Das","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ritesh Das","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#article","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/"},"author":{"name":"Ritesh Das","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd"},"headline":"How Do You Add Web Push to an Existing Service Worker?","datePublished":"2026-11-28T04:36:27+00:00","dateModified":"2026-11-28T04:36:27+00:00","mainEntityOfPage":{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/"},"wordCount":1382,"commentCount":0,"publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"image":{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg","articleSection":["How to"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/","url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/","name":"How Do You Add Web Push to an Existing Service Worker?","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage"},"image":{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg","datePublished":"2026-11-28T04:36:27+00:00","dateModified":"2026-11-28T04:36:27+00:00","breadcrumb":{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322000000"},{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322001111"},{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322002222"},{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322003333"},{"@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322004444"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#primaryimage","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-with-existing-service-worker.jpg","width":1200,"height":675,"caption":"Illustration of web push added to an existing service worker, a gear cog connected to a cache, a bell and a puzzle piece"},{"@type":"BreadcrumbList","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/larapush.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How Do You Add Web Push to an Existing Service Worker?"}]},{"@type":"WebSite","@id":"https:\/\/larapush.com\/blog\/#website","url":"https:\/\/larapush.com\/blog\/","name":"LaraPush Blog","description":"Stay Ahead, Stay Notified with LaraPush!","publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/larapush.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/larapush.com\/blog\/#organization","name":"LaraPush","url":"https:\/\/larapush.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png","width":280,"height":60,"caption":"LaraPush"},"image":{"@id":"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd","name":"Ritesh Das","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g","caption":"Ritesh Das"},"url":"https:\/\/larapush.com\/blog\/author\/riteshdas\/"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322000000","position":1,"url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322000000","name":"Can a website have two service workers?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"A site can have several registrations, but each scope has only one active service worker. Two workers at the same scope replace each other. Workers at different scopes can coexist, but each only controls pages inside its own path, which makes push and caching harder to manage.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322001111","position":2,"url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322001111","name":"Does adding push code slow down my service worker?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Not noticeably. Push and notificationclick listeners only run when those events fire, so they don't affect page loads or fetch handling. The main cost is the extra script download the first time the worker installs or updates.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322002222","position":3,"url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322002222","name":"Can I use importScripts() in a module service worker?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"No. importScripts() only works in classic service workers. If you register your worker with type module, use standard import statements to bring in the push code instead, and check that your target browsers support module service workers.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322003333","position":4,"url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322003333","name":"Why did push stop working after I installed a PWA plugin?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The PWA plugin probably registered its own service worker at the root scope, replacing your push worker. Merge both into one file, or use the plugin's option to import extra scripts, then confirm in DevTools that one worker handles both caching and push.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322004444","position":5,"url":"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/#faq-question-1764322004444","name":"Do I need firebase-messaging-sw.js to use FCM on the web?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"No. That's only the default file name the Firebase SDK looks for. Pass your own service worker registration to getToken() with the serviceWorkerRegistration option, and put the messaging or push handler code in your existing worker.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3603"}],"collection":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/comments?post=3603"}],"version-history":[{"count":1,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3603\/revisions"}],"predecessor-version":[{"id":3611,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3603\/revisions\/3611"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media\/3610"}],"wp:attachment":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media?parent=3603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/categories?post=3603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/tags?post=3603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}