Sam S.
Sam S.

Reputation: 153

Ask an API periodically for data in the background when the PWA is closed?

I'm a student and planning to make an progressive web app, which should display the newest movies. The data will be received trough the API of TheMovieDB and stored in IndexedDB to make the content offline available.

My idea was to show the user push notifications when new movies added while the app is closed. Since TheMovieDB doesn't send push notifications I need to ask the TheMovieDB-API in the background (through a Service Worker?), get the list of movies, check if new titles added (compared with the list in the IndexedDB) and generate a push notifitcation which shows the new added titles.

Can I make a Service Worker which makes periodically (every 4h) requests in the background to the TheMovieDB-API? or are there other better solutions for this kind of problem?

Upvotes: 4

Views: 1485

Answers (1)

abraham
abraham

Reputation: 47923

Service Workers only support reacting to events. They do not support timers or periodic syncs. You're best option is to run a server that checks for updates and then sends a push notification as needed. There are some proposed standards but they have not been implemented yet.

Upvotes: 4

Related Questions