Book Image

Service Worker Development Cookbook

By : Sean Amarasinghe
Book Image

Service Worker Development Cookbook

By: Sean Amarasinghe

Overview of this book

It would be nice to have web apps that work offline and send push notifications. This is now possible with Service Workers, which can add native-like functionality to your web apps without requiring a download. This book will get your mobile and web apps functioning without Internet connectivity, improve performance and network interaction in order to increase the level of availability, and show you how to build performant applications that seamlessly integrate with third-party APIs. We’ll show you how to add Service Worker functionality to web apps and sites, access offline content through basic and advanced techniques, and build powerful interactive system notifications. We’ll also teach you about cache functionality and assets to provide immediate load even over narrow connections. We conclude by giving you various tips to improve app performance, including the background sync technique. By the end of this book, you’ll know build high performing and faster web and mobile applications with Service Workers.
Table of Contents (17 chapters)
Service Worker Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Showing rich notifications


Rich push notifications can send images, vibration patterns, and localized notifications. Let's look at how we can achieve this.

Getting ready

To get started with service workers, you will need to have the service worker experiment feature turned on in your browser settings. If you have not done this yet, refer to the Setting up service workers recipe of Chapter 1, Learning Service Worker Basics. Service workers only run across HTTPS. To find out how to set up a development environment to support this feature, refer to the Setting up GitHub pages for SSL recipe of Chapter 1, Learning Service Worker Basics.

How to do it...

Follow these instructions to set up your file structure:

  1. Copy the index.html, index.js, service-worker.js, manifest.json, server.js, package.json, amazon-logo.png, and style.css files from the following location:

    https://github.com/szaranger/szaranger.github.io/blob/master/service-workers/08/03/

  2. Open a browser and go to index.html.

  3. You can change the...