O'Reilly logo

Building Progressive Web Apps by Tal Ater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Service Workers: A Great Opportunity to Adopt ES2015

ECMAScript 2015 (also known as ES2015, ES6, and ES6 Harmony) is the 2015 update to the ECMAScript language specification—the specification that JavaScript implements—and the first major update to it since ES5 in 2009.

ES2015 adds many new language features to ECMAScript (and thus, to JavaScript), including arrow functions, constants, promises, classes, modules, for/of loops, template strings, and much more.

Quite simply, it makes writing JavaScript a much more pleasant experience and helps you write more elegant code.

Unfortunately for developers looking to write with ES2015, many users still use older browsers that do not fully support ES2015.

This problem can be solved by transpiling ES2015 code to older ES5 code at build time using a tool like Babel. This process takes your code and changes any syntax that isn’t compatible with ES5 into one that is compatible. Unfortunately, adding this extra build step is something many developers are not comfortable with, or choose not to do, and so they are unable to enjoy these new language features.

Service workers, however, provide a great opportunity to get started with ES2015. As all browsers that currently implement service workers also implement most ES2015 features, you can safely use these new features in your service worker file—no transpilation needed.

We have already used a few ES2015 features in our service worker, including promises, string.includes(), string.startsWith() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required