Periodic Background API
Published on April 15, 2021← Back to tips
Lets you run specific tasks at custom intervals, like a cronjob but in your browser.
Useful to provide a seamless and fast web experience
- Prefetch changed contents on the page without any action from user, for faster reloading/refresh; Can also use to update offline cache
- Retrieve and batch notifications for UI
- The API is only usable in a progressive web app (PWA)
- Can only run the code in your service worker. You might need to use a postMessage to communicate with client/window
How to use:
- Request permissions
- Once granted, register a sync with an interval
- Add an event listener for the custom sync event to trigger the action
🎉 Interested in Frontend or Indie-hacking?
I talk about the latest in frontend, along with my experience in building various (Indie) side-projects