Tips for setting up offline alerts using a progressive web application

I have been working on implementing reminder notifications for my progressive web app, which was originally built as a Nextjs site. The specific criteria I need to meet are:

  • Functionality even when the device is offline
  • Accurate notifications within seconds
  • Ability to work when the app is in the background
  • Support for delays ranging from several minutes to several hours

Initially, I focused on using a service worker with a handler for the message event. I used event.waitUntil to prolong the life of the service worker for notifications by incorporating a delay from Bluebird's Promise.delay.

This method worked well until the service worker was terminated around the 5-minute mark after the app was sent to the background, as outlined in the documentation. Many others have encountered this limitation as well, so I have explored various workarounds.


The accepted answer to this question lists several development options from 2019:

Periodic Background Sync API

This API allows scheduling periodic events while the app has network connectivity. However, it relies on a site's engagement score to determine the rate of syncs, lacks offline support, and is not supported by Firefox and Safari browsers, making it unsuitable for my needs.

Notification Triggers

Notifications can be triggered to show up at specific times, but the issue tracking this feature has been unresolved since 2018.

Scheduled Task API

This API permits running tasks without requiring connectivity, but it has been deprioritized.


Additional options beyond using a service worker are detailed in this resource.

Dedicated Worker Relay

This method involves holding calls to the service worker in a dedicated worker and passing them along when the notifications are due. However, this solution is not functional for mobile due to lifespan limitations.

Shared Worker Relay

Similar to Dedicated Worker Relay, but utilizing a Shared Worker, which is not supported on mobile.


Other potential workarounds include:

  • Developing a native wrapper or variant that must be distributed through an app store, eliminating the PWA aspect and requiring a store deployment
  • Implementing push notifications, although this approach necessitates the service managing client timers and sacrifices offline functionality

I am still seeking ways to enable offline notifications. I have explored whether keeping a notification open can sustain the service worker's lifespan (as native apps do) and if there are any special permissions that can extend service worker longevity, but I have not made progress on these fronts yet.

Has anyone achieved success in achieving this kind of functionality?

Answer №1

If you're looking to set up offline notifications for your progressive web app, you have a couple of options at your disposal. One method involves leveraging the power of the Service Worker API, while another approach is to utilize a tool such as Workbox.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unveiling the secret to accessing properties using v-if within a custom component template relocation

I'm currently working on an application that reveals a hidden div when the text "Create Test" is clicked. Everything works well when the code isn't placed inside the template of a component. This seems strange to me, what could be causing this is ...

Is there a way to access data from a different cart template containing personalized values on Shopify?

After analyzing the values required from product.json, I realized that the current method is not efficient. The client-side ends up processing unnecessary information and every new product or option adds to the request load. Below is the script responsible ...

Change a TypeScript alias within the @types namespace

While using Typescript 3, I encountered a situation where I needed to modify a type alias from the @types/json-schema definition provided by DefinitelyTyped. The issue arose when I wanted to incorporate a custom schema type into my code. Since this custom ...

Exploring time differences in Javascript

I am trying to save a JSON AJAX response from the server in the browser's localStorage for a duration of one minute, along with a timestamp generated using new Date().getMinutes(). Upon triggering $(document).ready, I aim to check the stored timestam ...

What is the best way to automatically select a checkbox when using ng-repeat on page

I'm looking to automatically check an input checkbox when the page loads, and if it's checked, subtract its value from the total. How can I tackle this issue? Here's the HTML snippet: <p>{{vm.TOTAL VALUE}}</p> <tr ng-repeat= ...

Using Node.js to alter an existing JSON file

I have a file named a1.json that contains the following data: { "Key1" : [ { "Key11" : "Value11" , "Key12" : "Value12" }, { "Key21" : "Value21" , "Key22" ...

Update the router URL without switching pages, yet still record it in the browser history

One of the features on my search page allows users to perform searches and view results. Initially, I faced a challenge in updating the router URL without navigating, but I managed to overcome this by utilizing the "Location" feature. In my ngOnInit meth ...

Fill an HTML div with JSON data obtained from a server

I am trying to display JSON data from a json-rpc server inside an HTML div. I can see the data in Chrome and Firefox dev tools, but I need it to be displayed within a specific div on the page. I have written a script to populate the 'mybox' div, ...

I've been attempting to adjust the font color, but for some unknown reason, it simply won't cooperate

I am really struggling with changing the color of text in my p tag. As a beginner in coding, any advice or guidance would be greatly appreciated. import React from 'react' import { SocialIcon } from 'react-social-icons'; type Props = ...

Error in NVD3 causing charts to be inaccurately rendered

While utilizing a stacked area chart in the Stacked display mode, there appears to be an issue with the shading under the graph, particularly on the left side of the displayed plot below. We are currently working with d3 v3.4.9 and nvd3 v1.1.15b. Do you ...

Create a new variable to activate a function within the parent component in Vue

I want to invoke a function in the parent component from its child component. In my Vue project, I have designed a reusable component that can be used across multiple pages. After the function is executed in this component, I aim to call a specific functi ...

Can a `react` app with `mysql` be uploaded to `github`?

I recently created a basic online store with the help of react, node, and mysql. I am considering uploading it to github, but I'm uncertain if I can do so while my database is currently stored on localhost. Any advice? ...

"Successful implementation of Ajax function in local environment but encountering issues when running online

I am facing an issue with my AJAX function. It works perfectly fine on my local server but does not return anything when I move it to my online server. Below is the code snippet: This is the part of the page where I call the showEspece() function: echo ...

(React) Error: Unable to access property 'this' as it is set to undefined while trying to utilize refs

When using a ref in React to refer to an input field, I encountered an error: "Uncaught TypeError: Cannot read property 'this' of undefined". Despite having defined the ref, React seems unable to locate it in my code. What could be causing this i ...

Troubleshooting undefined results with AngularJS ng-repeat filter

My objective is to create a Letter Filter, where users can click on buttons from A to Z to filter the displayed data. When clicking on the letter 'A' button, only data starting with 'A' should be shown. However, I have encountered an i ...

What sets apart custom events from postMessage?

If you want to send a message to another document, such as an iframe, there are two functions you can use - postMessage and createEvent. Consider the following: var event = document.createEvent('CustomEvent'); event.initCustomEvent("message", tr ...

Changing the background color of required inputs that are empty using jQuery

I need help customizing the background color of required input fields that are left empty when a user submits a form. Some of the fields are optional, but I want only the required ones to be highlighted in red. Specifically, the required fields have been ...

Mastering the art of effectively capturing and incorporating error data

Is there a way to retain and add information to an Error object in typescript/javascript without losing the existing details? Currently, I handle it like this: try { // code that may throw an error } catch (e) { throw new Error(`Error while process ...

jQuery Algorithm for calculating totals

Here is an algorithm for formatting amounts using jQuery: Visit jsfiddle for the code However, there are some issues. For instance, if I enter 900.800,00 and then delete the "9", it still displays 00.800,00. How can this be resolved? I have fixed severa ...

The issue of `Console.log` displaying as undefined arises after subscribing to a provider in Ionic3

In the process of implementing the Spotify api into my Ionic 3 app, I encountered an issue where the data retrieved appears as undefined when attempting to log it. Let me share some code and delve deeper into the problem. Here is the function getData() tha ...