Book Image

Progressive Web Application Development by Example

By : Chris Love
Book Image

Progressive Web Application Development by Example

By: Chris Love

Overview of this book

Are you a developer that wants to create truly cross-platform user experiences with a minimal footprint, free of store restrictions and features customers want? Then you need to get to grips with Progressive Web Applications (PWAs), a perfect amalgamation of web and mobile applications with a blazing-fast response time. Progressive Web Application Development by Example helps you explore concepts of the PWA development by enabling you to develop three projects, starting with a 2048 game. In this game, you will review parts of a web manifest file and understand how a browser uses properties to define the home screen experience. You will then move on to learning how to develop and use a podcast client and be introduced to service workers. The application will demonstrate how service workers are registered and updated. In addition to this, you will review a caching API so that you have a firm understanding of how to use the cache within a service worker, and you'll discover core caching strategies and how to code them within a service worker. Finally, you will study how to build a tickets application, wherein you’ll apply advanced service worker techniques, such as cache invalidation. Also, you'll learn about tools you can use to validate your applications and scaffold them for quality and consistency. By the end of the book, you will have walked through browser developer tools, node modules, and online tools for creating high-quality PWAs.
Table of Contents (12 chapters)

Service worker events

A service worker has several events. You can use these to manage your application's cache. We have already looked at using the install and activate events to precache responses in Chapter 5, The Service Worker Life Cycle.

The all-star service worker event is fetch. This event fires each time a network-addressable asset (URL) is requested. By adding a fetch event handler to your service worker, you can intercept all network requests, triggering a workflow to determine how to respond:

self.addEventListener("fetch", event => { 
   //process request and return best response 
}); 

As you learned Chapter 6, Mastering the Cache API – Managing Web Assets in a Podcast Application, you can use the Fetch API's custom request and response objects to inspect requests and create or clone network responses.

The event variable supplied by the...