Tomáš Zato
Tomáš Zato

Reputation: 53129

Can an offline JavaScript app using service workers work after browser restart?

Application cache as a means of creating offline browser apps has been deprecated. The current way to make an offline web app is to use service workers.

Service workers allow you to bootstrap all network requests and provide content for them. Since service worker can run even when user closes the tab, it can provide cached content when internet temporarily doesn't work.

However when I got interested in offline web applications, it was because I hoped to use even when I have permanently no access to internet. I created simple offline app, but it does not work when I close and open the browser — I get message that page cannot be loaded.

Is there a way to make service worker offline app work even after browser is closed and re-opened? If not, are there any planned standards for this? It would be very valuable to mobile users.

Upvotes: 6

Views: 2157

Answers (2)

meskobalazs
meskobalazs

Reputation: 16041

There is a great deal of development in the area of service workers. Chrome is taking the lead, but Firefox follows closely. IE support is negligible however.

You can see the W3C working draft. For browser support, check e.g. here.

I also suggest taking a look at Nolan Lawson's pokedex.org application, it is an offline-capable web app based on service workers.

Upvotes: 1

T.J. Crowder
T.J. Crowder

Reputation: 1074208

Can an offline JavaScript app using service workers work after browser restart?

Yes, it can, provided it's cached all of its resource previously. This example goes through the steps of ensuring that.

The reason it can is that when you navigate to the URL that the service worker is registered for, the cached copy of the service worker is activated and it's given the opportunity to satisfy network requests for the app. So if you've cached everything, and you satisfy all of the requests by handling the fetch event, your app can be entirely offline.

Upvotes: 3

Related Questions