Get­ting apps to work off­line

Web Designer - - Build Progressive Web Apps With Workbox -

One of the big­gest bar­ri­ers to pro­vid­ing a true na­tive-like ex­pe­ri­ence from a web app is de­pen­dency on the net­work. It’s no good for the user if the app only works with an in­ter­net con­nec­tion. Na­tive apps can be loaded up even when the de­vice is com­pletely off­line, and don’t fail dur­ing pe­ri­ods of in­ter­mit­tent con­nec­tion (think about when you’re on the train…). For­tu­nately, the Ser­vice Worker API solves this. A ser­vice worker is a piece of Javascript code down­loaded with a page that is stored by the browser and runs in the back­ground – even when the page isn’t be­ing viewed. It al­lows you to in­ter­cept net­work re­quests (such as fetch­ing a URL) and de­ter­mine how to han­dle them. When com­bined with the Cache API, this en­ables you to de­cide when and how to serve up cached con­tent if a net­work con­nec­tion is not avail­able. As a re­sult, it is now pos­si­ble to de­velop web apps which, once down­loaded and cached, can be used en­tirely off­line. Be­cause you de­fine the be­hav­iour for each and ev­ery re­quest, you can also be­gin to im­ple­ment more com­plex caching strate­gies. For ex­am­ple, you might de­cide to serve from the cache im­me­di­ately but also re­fresh the cache from the net­work in the back­ground, so that next time the same page is re­quested, the data is more up to date.

Newspapers in English

Newspapers from UK

© PressReader. All rights reserved.