I want to make an AJAX request every 10 seconds, even when the page is closed, to send notifications like Facebook, when it sends notifications with the tab closed.
I guest I can accomplish this with service workers. I have tried doing this:
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js').then(function(registration) {
    console.log('ServiceWorker registration successful with scope: ', registration.scope);
  })
  .catch(function(err) {
    console.log('ServiceWorker registration failed: ', err);
  });
}
But I don't know how to send an AJAX call in sw.js.
Thanks, and sorry for my bad English.
 
    