Lets you run specific tasks at custom intervals, like a cronjob but in your browser.
Useful to provide a seamless and fast web experience
Use Cases:
- 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
Some Limitations:
- 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
More reading
🎉 Interested in Frontend or Indie-hacking?
I talk about the latest in frontend, along with my experience in building various (Indie) side-projects