Offline with service worker
serviceworker-rails gem
After trying the rack-offline and realize that we need to search a method that implement the offline feature for multiple page application. I found one another method that is Service Worrker technology of HTML 5 basically service woker is the javascript API for making the multiple pages work offline. Now for using this API in rails, I found serviceworker-rails gem that helps to use the service worker method in the rails app. Now find some tutorails proposed by the owner of the serviceworker-rails to implement it in the rails app. j
Implementing the serviceworker-rails gem
After searching about this method, I discuss this with my mentors and they appreciated this method. So I started working on it. I create a new page in the public directory to simple cache the assets. While registering the service worker it shows me some errors as there is some code that arise this errors to not register the service worker on the web. When we register the serviceworker then I store the data in the cache when the user visits the application then we use the data when app is not connected to the internet.
But now I focus on to show the pages that are in the views to be offline I tried this with the documentation of serviceworker-rails app. But now the problem is that the data it shows while we are not connected to the internet is static but the views of our application is totally include the dynamic content our application has multiple pages and we want them all work offline. So I was little confused :(. So I concern this with the owner of the serviceworker-rails gem and also create a new issue https://github.com/rossta/serviceworker-rails-sandbox/issues/2#event-736530467
Also tried to get the help from the rubyonrails then ask the queries in the mailing list after that ask the query on the stack overflow and also mailed to the every owner of the blog post related to the offline, but did not get the reply :(.Then I found actionpack-action_caching gem then read documentation of this method and found that this method is for the server caching not for caching the data. So it might be used to speed up the application but not for the offline work. I asked this to my mentors they also don’t have any idea related to this. Saumya (my mentor) told me to discuss this with rosario-robinson and she referred me Sylvain Abelar and we discuss all the aspects and the method we tried.
What should I load when I still have network?
This is for the first time when the application firstly load in the browser. Which data we want to store offline. We want enough data but not too much.
What should I do when I don’t have network?
When the application is not connected to the internet. As Abelan said searching is hard, creating is fine but we need to check it, making for deletion or edition is fine.
What should I do when I have network back?
When the application connected to the internet then it send all the modifications to the server, this is also possible to send the modification with the timestamp and a “log/reporting” thing. As we already add this feature in our application.
Then he said suggest me two methods:
- OPAL
- SPA using ember