I am building a javascript Web Application. In there i want to upload pictures and other data to a server. This is all working, but i want to use the application offline as well. Therefore i implemented the indexedDB, to store the data offline. Furthermore i made a sync-function, which will be executed every 5 seconds (setIntervall()...) to syncronise the data to the server if there is a internet connection again.
The problem is, that this sync-function only works when the app is open. So I researched a method to solve my problem and i got the idea of a "service worker" with background sync.
The problem is i don't know how to implement it.
This is what i currently have (the whole app is programmed in MVC-concept):
- I have a sw.js with the following code:
if (event.tag == 'myFirstSync') {
event.waitUntil(sync());
}
});
- In the controller there is the function sync() for synchronising the data