ServiceWorkers and Firefox

Since early 2013, Mozillians have been involved with the design of the Service Worker. Thanks to work by Google, Samsung, Mozilla, and others, this exciting new feature of the web platform has evolved to the point that it is being implemented in various web browser engines.

What are Service Workers?

At their simplest, Service Workers are scripts that act as client-side proxies for web pages. JavaScript code can intercept network requests, deliver manufactured responses and perform granular caching based on the unique needs of the application, a feature that the web platform has lacked before now. This powerful capability being made available to web developers enables, among other things, the creation of fully-functioning offline experiences. Jake Archibald has summarized some of these features in his blog post.

Since Service Workers run in the “background”, they open up several possibilities for the Web that were previously only available on native platforms. Apart from the networking capabilities provided by the base specification, Service Workers are intended to be used by the Push API and the Background Sync API to deliver messages from the user-agent to web applications.

Service Workers in Firefox

A number of Mozillians have been hard at work implementing Service Workers in Gecko while Anne van Kesteren and Jonas Sicking help with the design and specification. Members of the Necko team and others have provided input from networking and related perspectives. Nikhil Marathe recently published a blog post about the status of Service Workers in Gecko.

The Service Worker implementation in Gecko is landing in pieces as soon as they are finished and reviewed. For the time being, as the specification continues toward stability and other implementations — notably Blink’s — progress, all functionality in Gecko is behind the dom.serviceWorkers.enabled preference which is set to false by default but can be toggled in about:config.

Our plan is that web developers will soon be able to exercise most Service Worker functionality in Firefox Nightly with the above preference flipped to true. The best plans can always be waylaid but we hope for this to happen by the end of September 2014 at the latest.

Status of Service Worker implementations

The inimitable Jake Archibald has written a tool to easily see the status of Service Worker implementations. You can follow along with the gecko implementation via the meta bug.

About Nikhil Marathe

Nikhil is a Platform Engineer at Mozilla. He likes technical writing, having written 'An Introduction to libuv', and blogs at http://blog.nikhilism.com. He can be found working when he is not hiking, climbing or reading.

More articles by Nikhil Marathe…

About Andrew Overholt

Andrew is an engineering manager on the DOM team at Mozilla.

More articles by Andrew Overholt…

About Robert Nyman [Editor emeritus]

Technical Evangelist & Editor of Mozilla Hacks. Gives talks & blogs about HTML5, JavaScript & the Open Web. Robert is a strong believer in HTML5 and the Open Web and has been working since 1999 with Front End development for the web - in Sweden and in New York City. He regularly also blogs at http://robertnyman.com and loves to travel and meet people.

More articles by Robert Nyman [Editor emeritus]…


4 comments

  1. Filip Bech-Larsen

    How does the above to firefox OS?

    June 26th, 2014 at 00:34

    1. Nikhil

      Most of this functionality will be available in Firefox OS too at the same time it lands in Firefox Desktop. We don’t have a clear picture right now, but some APIs may be temporarily disabled while we get better performance on hardware constrained devices.

      June 27th, 2014 at 11:17

  2. Ivan Dejanovic

    I barely managed to come to grips with app cache and now you are killing it with Service Worker. :)

    On the serious note. I read in couple of places that Service Worker with among other things replace app cache as the tool for providing offline capabilities to web apps. Unfortunately I was not able to try out Service Worker yet due to being busy with other work. How will this affect me as a Web and Firefox OS developer. I already have an app in Firefox marketplace and two more that are 95% done. All three use app cache for offline support.

    Will they continue to work as is in the future or will modifications be required? What is the plan for app cache? Will it be decommissioned? What should I use in my future apps since Service Worker is still not fully supported and app cache is implemented in all major browsers. Is there any time table when this will be available in non nightly Firefox?

    Thank you for all your great work.

    June 26th, 2014 at 06:49

    1. Nikhil

      Gecko doesn’t have any plans to deprecate or remove AppCache currently, so you can continue to use it if it suits your needs. The intent of ServiceWorkers is to allow more granular and easy to understand control over offline mechanisms.

      As stated above, if everything goes well, we intend to land most of the pieces by end of September, so that they will be available in release builds by the end of the year.

      June 27th, 2014 at 11:21

Comments are closed for this article.