For an introduction to PWAs and a business case for why we should start using them, please take a look at my previous article: An Introduction to Progressive Web Apps.
Progressive Web Apps are a new set of technologies and guidelines which allow web developers to create engaging and performant web applications that can compete with native mobile apps. In this article I’m going to talk through some of the technologies which are available to us, outline browser support for each of the features and show a few code snippets which make use of the APIs a little.
Barely in its infancy, the technology is already reaping benefits for some large businesses. Companies like Alibaba and Flipkart have seen a significant increase in retention and conversion rates thanks to PWA. It is likely to have even greater benefits for people in developing countries using 2G and 3G networks on devices with little storage by providing them with faster and more reliable access to the web. It would make sense for many businesses tapping to these markets to take advantage of PWAs as well.
With this in mind, learning how to use Progressive Web Apps now, while the technology is still in its early stages, will help you get ahead of the curve and acquire valuable skills that will be increasingly in demand as PWAs take off.
Service Workers
Service workers are an integral part to making your PWA and arguably the most important technology as some of the APIs listed below are reliant on having an installed Service Worker.
It is essentially a script which is created by web developers that can be installed on the user’s browser and grants access to do actions in the background that developers wouldn’t usually be able to do. For example, it can act as a middle tier and intercept requests to the server, or run background tasks to sync data from a server to update the cache, or listen to push notifications. All of this can be done when the browser isn’t open on the device, so it’s a very powerful item in your toolbox.
The most common use of a service worker is to enable offline support and to improve speed of your site. Your service worker can be setup to intercept requests from the client to the server, check if the resource is stored in your app cache and deliver the cached resource instead of making a request to the server. This is exactly how you enable offline support on your app. If you couple Service Workers with IndexDB, you can make an app which caches data as well as the main site files to make a truly offline app.