{"id":3413,"date":"2026-11-15T10:05:08","date_gmt":"2026-11-15T04:35:08","guid":{"rendered":"https:\/\/larapush.com\/blog\/?p=3413"},"modified":"2026-11-15T10:05:08","modified_gmt":"2026-11-15T04:35:08","slug":"add-web-push-notifications-to-nextjs","status":"publish","type":"post","link":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/","title":{"rendered":"How to Add Web Push Notifications to a Next.js Site"},"content":{"rendered":"\n<p><strong>To add web push notifications to a Next.js site, put a service worker file in the public folder, generate VAPID keys, and ask for permission from a button click.<\/strong> Then save each push subscription in a database and send messages from a Server Action or API route with the web-push library. Or use a push platform&#8217;s script and service worker.<\/p>\n\n\n\n<p>Next.js web push notifications follow the same W3C standards as any other site, so there&#8217;s nothing Next.js-specific about delivery. What Next.js changes is where files live and where server code runs. Below I cover both routes, the DIY build and the platform route, and the mistakes I see most often.<\/p>\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\/add-web-push-notifications-to-nextjs\/#What_do_you_need_to_add_web_push_to_Nextjs\" title=\"What do you need to add web push to Next.js?\">What do you need to add web push to Next.js?<\/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\/add-web-push-notifications-to-nextjs\/#How_do_you_build_it_yourself_step_by_step\" title=\"How do you build it yourself, step by step?\">How do you build it yourself, step by step?<\/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\/add-web-push-notifications-to-nextjs\/#Where_should_the_service_worker_file_live\" title=\"Where should the service worker file live?\">Where should the service worker file live?<\/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\/add-web-push-notifications-to-nextjs\/#How_do_you_handle_permission_in_a_React_component\" title=\"How do you handle permission in a React component?\">How do you handle permission in a React component?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#Does_Nextjs_web_push_work_on_iPhone\" title=\"Does Next.js web push work on iPhone?\">Does Next.js web push work on iPhone?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#Should_you_build_it_yourself_or_use_a_push_platform\" title=\"Should you build it yourself or use a push platform?\">Should you build it yourself or use a push platform?<\/a><\/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\/add-web-push-notifications-to-nextjs\/#Where_does_LaraPush_fit\" title=\"Where does LaraPush fit?\">Where does LaraPush fit?<\/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\/add-web-push-notifications-to-nextjs\/#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=\"What_do_you_need_to_add_web_push_to_Nextjs\"><\/span>What do you need to add web push to Next.js?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You need five pieces, and the official <a href=\"https:\/\/nextjs.org\/docs\/app\/guides\/progressive-web-apps\" target=\"_blank\" rel=\"noreferrer noopener\">Next.js PWA guide<\/a> walks through each of them for the App Router.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Piece<\/th><th>Where it goes in Next.js<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td>HTTPS<\/td><td>Your hosting (localhost is fine for testing)<\/td><td>Push and service workers need a secure context<\/td><\/tr><tr><td>Service worker<\/td><td>A file in \/public, served from your domain<\/td><td>Receives push events and shows notifications<\/td><\/tr><tr><td>VAPID key pair<\/td><td>Environment variables<\/td><td>Identifies your server to push services<\/td><\/tr><tr><td>Subscribe UI<\/td><td>A client component<\/td><td>Requests permission on a click and creates the subscription<\/td><\/tr><tr><td>Sender<\/td><td>A Server Action or route handler<\/td><td>Stores subscriptions and sends messages<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Keep the private VAPID key server-side only. In Next.js, any variable prefixed with NEXT_PUBLIC_ is exposed to the browser, so only the public key gets that prefix. My post on <a href=\"https:\/\/larapush.com\/blog\/vapid-keys-web-push\/\">VAPID keys for web push<\/a> explains what each key does.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_build_it_yourself_step_by_step\"><\/span>How do you build it yourself, step by step?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Build it in seven steps. This is the route the Next.js guide uses, with the open-source <a href=\"https:\/\/github.com\/web-push-libs\/web-push\" target=\"_blank\" rel=\"noreferrer noopener\">web-push library<\/a> on the server.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install web-push and run its generate-vapid-keys command.<\/li>\n\n\n\n<li>Save the keys as NEXT_PUBLIC_VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY in your .env file.<\/li>\n\n\n\n<li>Create a service worker in \/public that listens for push and notificationclick events.<\/li>\n\n\n\n<li>In a client component, register the service worker and check that PushManager is supported.<\/li>\n\n\n\n<li>On a button click, call pushManager.subscribe with userVisibleOnly set to true and your public key.<\/li>\n\n\n\n<li>Send the subscription to a Server Action that stores it in your database.<\/li>\n\n\n\n<li>Send messages from the server with webpush.sendNotification, then remove subscriptions that return 404 or 410.<\/li>\n<\/ol>\n\n\n\n<p>The Next.js guide stores a single subscription in memory to keep the example short. As its own comments note, a real app needs a database, or every restart loses your subscribers. For the protocol details behind step 7, see MDN&#8217;s <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Push_API\" target=\"_blank\" rel=\"noreferrer noopener\">Push API reference<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_should_the_service_worker_file_live\"><\/span>Where should the service worker file live?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Put it in the public folder so Next.js serves it as a static file from your own domain, such as \/sw.js. A service worker controls only pages within its scope, and by default the scope is the folder it&#8217;s served from, so the site root covers everything.<\/p>\n\n\n\n<p>Don&#8217;t bundle it into your JavaScript chunks or serve it from a CDN on another domain. Browsers require the service worker to come from the same origin as your site. Also, avoid caching it aggressively, or fixes won&#8217;t reach users quickly. My guide to <a href=\"https:\/\/larapush.com\/blog\/service-worker-for-web-push\/\">the service worker for web push<\/a> covers scope and caching in more detail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_handle_permission_in_a_React_component\"><\/span>How do you handle permission in a React component?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Request permission only from a user action, such as a button&#8217;s onClick handler. Calling it in useEffect on page load fails on iPhone, where WebKit only shows the prompt in response to a tap, and it annoys visitors on every other browser.<\/p>\n\n\n\n<p>Also, check for support before showing the button. Service workers and PushManager only exist in the browser, so run these checks in a client component, never during server rendering. MDN&#8217;s <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Notification\/requestPermission_static\" target=\"_blank\" rel=\"noreferrer noopener\">Notification.requestPermission() reference<\/a> covers the API. For copy and timing, see my notes on <a href=\"https:\/\/larapush.com\/blog\/push-permission-prompt-best-practices\/\">push permission prompt best practices<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Does_Nextjs_web_push_work_on_iPhone\"><\/span>Does Next.js web push work on iPhone?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Yes, on iOS 16.4 and later, if the site is added to the Home Screen. For that, you need a web app manifest with display set to standalone. Next.js can generate one from an app\/manifest.ts file, as its PWA guide shows.<\/p>\n\n\n\n<p>The guide also includes an install prompt component that shows iPhone users how to add the site to the Home Screen. That banner matters, because Safari tabs can&#8217;t subscribe. For the full iPhone checklist, see <a href=\"https:\/\/larapush.com\/blog\/how-to-get-web-push-working-on-iphone\/\">how to get web push working on iPhone<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Should_you_build_it_yourself_or_use_a_push_platform\"><\/span>Should you build it yourself or use a push platform?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Build it yourself if you need a few transactional alerts and have developers to maintain them. Use a platform if marketing or editorial teams will send campaigns, because the DIY route gives you delivery but no dashboard.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Need<\/th><th>DIY with web-push<\/th><th>Push platform<\/th><\/tr><\/thead><tbody><tr><td>Send a simple alert from code<\/td><td>Good fit<\/td><td>Works too<\/td><\/tr><tr><td>Campaign editor, scheduling, templates<\/td><td>You build it<\/td><td>Included<\/td><\/tr><tr><td>Segments and click reports<\/td><td>You build it<\/td><td>Included<\/td><\/tr><tr><td>Handling expired subscriptions<\/td><td>You build it<\/td><td>Usually automatic<\/td><\/tr><tr><td>Ongoing cost<\/td><td>Developer time and hosting<\/td><td>Subscription or licence<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>With a platform, the Next.js work is small: add the platform&#8217;s script with the next\/script component, and place its service worker file in \/public. Then the platform handles subscriptions and sending. For a general overview of options, see <a href=\"https:\/\/larapush.com\/blog\/add-push-notifications-to-website\/\">how to add push notifications to a website<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_does_LaraPush_fit\"><\/span>Where does LaraPush fit?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaraPush is a self-hosted web push panel that works on any site that serves JavaScript, which includes Next.js apps. You add its script and service worker to your site, and it handles subscriptions, campaigns, scheduling, segmentation and reports. It also has a REST API with no call limits, so your Next.js server code can trigger sends. See the <a href=\"https:\/\/larapush.com\/features\/\">features overview<\/a> and the <a href=\"https:\/\/larapush.com\/guide\/\">setup guide<\/a>.<\/p>\n\n\n\n<p>The trade-offs: you run your own VPS, the licence covers one server, and there&#8217;s no free plan. Plans start from $499 one-time; check the <a href=\"https:\/\/larapush.com\/pricing\/\">pricing page<\/a> for current prices. If you&#8217;re comparing tools, my <a href=\"https:\/\/larapush.com\/blog\/best-push-notification-services-and-tools\/\">roundup of push notification services<\/a> covers SaaS and self-hosted options.<\/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-1763194000000\"><strong class=\"schema-faq-question\">Do I need a library to send web push from Next.js?<\/strong> <p class=\"schema-faq-answer\">Not strictly, but it&#8217;s much easier. Web push needs VAPID signing and payload encryption, which libraries like web-push handle for you. The official Next.js PWA guide uses web-push in a Server Action to send notifications.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763194001111\"><strong class=\"schema-faq-question\">Can I use web push with the Next.js Pages Router?<\/strong> <p class=\"schema-faq-answer\">Yes. Web push is a browser feature, so it doesn&#8217;t depend on the router. The service worker still goes in \/public, the subscribe logic runs in client-side code, and an API route replaces the Server Action for saving subscriptions and sending.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763194002222\"><strong class=\"schema-faq-question\">Why does my Next.js push prompt never appear?<\/strong> <p class=\"schema-faq-answer\">Usually because permission is requested on page load instead of on a click, the site isn&#8217;t on HTTPS, or the service worker failed to register. On iPhone, the site must also be added to the Home Screen before the prompt can appear.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763194003333\"><strong class=\"schema-faq-question\">Can I test Next.js web push on localhost?<\/strong> <p class=\"schema-faq-answer\">Yes. Browsers treat localhost as a secure context, so service workers and push work there without a certificate. iPhone testing, however, needs a real HTTPS deployment added to the Home Screen.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763194004444\"><strong class=\"schema-faq-question\">Is it safe to expose the VAPID public key in Next.js?<\/strong> <p class=\"schema-faq-answer\">Yes. The public key is meant to be shared with browsers, so the NEXT_PUBLIC_ prefix is fine for it. Never prefix the private key that way, because anything with NEXT_PUBLIC_ is bundled into client-side code.<\/p> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"How to add web push notifications to a Next.js site: service worker, VAPID keys, permission, sending, and when a push platform is easier.","protected":false},"author":7,"featured_media":3422,"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 to Add Web Push Notifications to a Next.js Site<\/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\/add-web-push-notifications-to-nextjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Add Web Push Notifications to a Next.js Site\" \/>\n<meta property=\"og:description\" content=\"How to add web push notifications to a Next.js site: service worker, VAPID keys, permission, sending, and when a push platform is easier.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/\" \/>\n<meta property=\"og:site_name\" content=\"LaraPush Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-15T04:35:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/\"},\"author\":{\"name\":\"Ritesh Das\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\"},\"headline\":\"How to Add Web Push Notifications to a Next.js Site\",\"datePublished\":\"2026-11-15T04:35:08+00:00\",\"dateModified\":\"2026-11-15T04:35:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/\"},\"wordCount\":1266,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg\",\"articleSection\":[\"How to\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/\",\"url\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/\",\"name\":\"How to Add Web Push Notifications to a Next.js Site\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg\",\"datePublished\":\"2026-11-15T04:35:08+00:00\",\"dateModified\":\"2026-11-15T04:35:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194000000\"},{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194001111\"},{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194002222\"},{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194003333\"},{\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194004444\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Illustration of Next.js web push notifications with a code editor, key and browser alert\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/larapush.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Add Web Push Notifications to a Next.js Site\"}]},{\"@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\/add-web-push-notifications-to-nextjs\/#faq-question-1763194000000\",\"position\":1,\"url\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194000000\",\"name\":\"Do I need a library to send web push from Next.js?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Not strictly, but it's much easier. Web push needs VAPID signing and payload encryption, which libraries like web-push handle for you. The official Next.js PWA guide uses web-push in a Server Action to send notifications.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194001111\",\"position\":2,\"url\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194001111\",\"name\":\"Can I use web push with the Next.js Pages Router?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. Web push is a browser feature, so it doesn't depend on the router. The service worker still goes in \/public, the subscribe logic runs in client-side code, and an API route replaces the Server Action for saving subscriptions and sending.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194002222\",\"position\":3,\"url\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194002222\",\"name\":\"Why does my Next.js push prompt never appear?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Usually because permission is requested on page load instead of on a click, the site isn't on HTTPS, or the service worker failed to register. On iPhone, the site must also be added to the Home Screen before the prompt can appear.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194003333\",\"position\":4,\"url\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194003333\",\"name\":\"Can I test Next.js web push on localhost?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. Browsers treat localhost as a secure context, so service workers and push work there without a certificate. iPhone testing, however, needs a real HTTPS deployment added to the Home Screen.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194004444\",\"position\":5,\"url\":\"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194004444\",\"name\":\"Is it safe to expose the VAPID public key in Next.js?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. The public key is meant to be shared with browsers, so the NEXT_PUBLIC_ prefix is fine for it. Never prefix the private key that way, because anything with NEXT_PUBLIC_ is bundled into client-side code.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Add Web Push Notifications to a Next.js Site","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\/add-web-push-notifications-to-nextjs\/","og_locale":"en_US","og_type":"article","og_title":"How to Add Web Push Notifications to a Next.js Site","og_description":"How to add web push notifications to a Next.js site: service worker, VAPID keys, permission, sending, and when a push platform is easier.","og_url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/","og_site_name":"LaraPush Blog","article_published_time":"2026-11-15T04:35:08+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg","type":"image\/jpeg"}],"author":"Ritesh Das","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ritesh Das","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#article","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/"},"author":{"name":"Ritesh Das","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd"},"headline":"How to Add Web Push Notifications to a Next.js Site","datePublished":"2026-11-15T04:35:08+00:00","dateModified":"2026-11-15T04:35:08+00:00","mainEntityOfPage":{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/"},"wordCount":1266,"commentCount":0,"publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"image":{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg","articleSection":["How to"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/","url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/","name":"How to Add Web Push Notifications to a Next.js Site","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage"},"image":{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg","datePublished":"2026-11-15T04:35:08+00:00","dateModified":"2026-11-15T04:35:08+00:00","breadcrumb":{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194000000"},{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194001111"},{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194002222"},{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194003333"},{"@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194004444"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#primaryimage","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/add-web-push-notifications-to-nextjs.jpg","width":1200,"height":675,"caption":"Illustration of Next.js web push notifications with a code editor, key and browser alert"},{"@type":"BreadcrumbList","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/larapush.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Add Web Push Notifications to a Next.js Site"}]},{"@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\/add-web-push-notifications-to-nextjs\/#faq-question-1763194000000","position":1,"url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194000000","name":"Do I need a library to send web push from Next.js?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Not strictly, but it's much easier. Web push needs VAPID signing and payload encryption, which libraries like web-push handle for you. The official Next.js PWA guide uses web-push in a Server Action to send notifications.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194001111","position":2,"url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194001111","name":"Can I use web push with the Next.js Pages Router?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes. Web push is a browser feature, so it doesn't depend on the router. The service worker still goes in \/public, the subscribe logic runs in client-side code, and an API route replaces the Server Action for saving subscriptions and sending.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194002222","position":3,"url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194002222","name":"Why does my Next.js push prompt never appear?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Usually because permission is requested on page load instead of on a click, the site isn't on HTTPS, or the service worker failed to register. On iPhone, the site must also be added to the Home Screen before the prompt can appear.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194003333","position":4,"url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194003333","name":"Can I test Next.js web push on localhost?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes. Browsers treat localhost as a secure context, so service workers and push work there without a certificate. iPhone testing, however, needs a real HTTPS deployment added to the Home Screen.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194004444","position":5,"url":"https:\/\/larapush.com\/blog\/add-web-push-notifications-to-nextjs\/#faq-question-1763194004444","name":"Is it safe to expose the VAPID public key in Next.js?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes. The public key is meant to be shared with browsers, so the NEXT_PUBLIC_ prefix is fine for it. Never prefix the private key that way, because anything with NEXT_PUBLIC_ is bundled into client-side code.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3413"}],"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=3413"}],"version-history":[{"count":1,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3413\/revisions"}],"predecessor-version":[{"id":3423,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3413\/revisions\/3423"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media\/3422"}],"wp:attachment":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media?parent=3413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/categories?post=3413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/tags?post=3413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}