It’s just data

Service Workers - First Impressions

Created by potrace 1.13, written by Peter Selinger 2001-2015

Successes, progress, and stumbling blocks encountered while exploring Service Workers.


The Apache Whimsy Board Agenda tool is designed to make ASF Board meetings run more smoothly. It does this by downloading all of the provided reports and collating them with comments, prior comments, action items, minutes, links to prior reports, links to committee information, and the like. It provides a UI to allow Directors and guests to enter comments. It provides a UI to allow the Secretary to take minutes.

The tool itself is built using React.JS. It starts by downloading all of the reports. Navigation between reports can be done via mouse clicks or cursor keys and doesn't involve any server interaction. As new data is received, the window is updated.

Finally, I'm new to Service Workers so I may be doing things in a profoundly dumb way. Any pointers would be appreciated. I am capable of RTFM and following examples.

First step - caching JSON

Some of the data (e.g., the list of ASF JIRA projects) is fetched on demand. Generally the page is first rendered using an empty list, and then updated once the actual list is received.

This process could be improved by caching the results received and using that data until fresh data arrives. As the Cache API is built on promises, and therefore asynchronous, this generally means rendering three times: once with a empty list, then with the cache, and finally with live data.

// retrieve an cached object.  Note: block may be dispatched twice,
// once with slightly stale data and once with current data
// Note: caches only work currently on Firefox and Chrome.  All
// other browsers fall back to XMLHttpRequest (AJAX).
JSONStorage.fetch = function(name, block) {
  if (typeof fetch !== 'undefined' && typeof caches !== 'undefined' && 
     (location.protocol == "https:" || location.hostname == "localhost")) {"board/agenda").then(function(cache) {
      var fetched = null;

      // construct arguments to fetch
      var args = {
        method: "get",
        credentials: "include",
        headers: {Accept: "application/json"}

      // dispatch request
      fetch("../json/" + name, args).then(function(response) {
        cache.put(name, response.clone());

        response.json().then(function(json) {
          if (!fetched || JSON.stringify(fetched) != JSON.stringify(json)) {
            if (!fetched) clock_counter--;
            fetched = json;
            if (json) block(json);

      // check cache
      cache.match(name).then(function(response) {
        if (response && !fetched) {
          response.json().then(function(json) {
            fetched = json;
            if (json) block(json);
  } else if (typeof XMLHttpRequest !== 'undefined') {
    // retrieve from the network only
    retrieve(name, "json", function(item) {return item.block})

All in all remarkably painless and completely transparent to the calling application. Doesn't involve the activation of Service Workers, but it doesn't have to.

Second step - caching HTML

What's true for JSON should also be true for HTML. Prior to the caching logic introduced above, and continuing to be true for browsers that don't support the service workers caching interface, data that should appear on the page would be missing briefly and show up a second or two later. In the case of HTML, that data would be the entire page. This would typically be seen both on the initial page load as well as any time a link is opened in a new tab.

The HTML case is both simpler and more difficult. Fetching the HTML from cache and then replacing it wholesale from the network, while possible, would be jarring. Fortunately, there already is logic in place to update the content of the pages based on updates received by XHR. So initially displaying where the user last left off, as well as updating the cache, is sufficient.

Unfortunately, it isn't quite so simple. I've included the current code below complete with log statements and dead ends.

// simple hashcode to prevent authorization from leaking
var hashcode = function(s) {
  return s && s.split("").reduce(
    function(a, b) {
      return ((a << 5) - a) + b.charCodeAt(0)


var status = {auth: null};

this.addEventListener("fetch", function(event) {
  var scope = this.registration.scope;
  var url = event.request.url;
  var path = url.slice(scope.length);
  var auth = hashcode(event.request.headers.get("Authorization"));

  if (/^\d\d\d\d-\d\d-\d\d//.test(path) && event.request.method == "GET") {
    console.log("Handling fetch event for", event.request.url);

    event.respondWith("board/agenda").then(function(cache) {
      return cache.match(path).then(function(cached) {
        if (cached) console.log("matched");
        console.log("auth", auth, status.auth);

        if (!auth || auth != status.auth) {
          // the following doesn't work
          cached = new Response("Unauthorized", {
            status: 401,
            statusText: "Unauthorized",
            headers: {"WWW-Authenticate": "Basic realm="ASF Members and Officers""}

          // fallback: ignore cache unless authorized
          cached = null

        if (cached) console.log("serving from cache");

        var network = fetch(event.request).then(function(response) {
          if (!cached) console.log("fetching from network");
          if (cached) console.log("updating cache");
          if (response.ok) cache.put(path, response.clone());
          status.auth = auth;
          return response

        return cached || network
  } else if (auth) {
    // capture authorization from other pages, if provided
    status.auth = auth

The primary problem is that the board agenda tool requires authentication to use as the data presented may contain Apache Software Foundation confidential information.

Without accounting for this, what often would be placed into the cache would be the HTTP 401 challenge response. That's not desirable.

Attempting to force the return of a challenge when an Authorization header is not present results in the display of the challenge response. Again, not what we want.

Falling back to only providing the cached data when the Authorization header is present (and matches the one used for the cache) results in the cache being used sometimes with Firefox. And, unfortunately, never with Chrome.

A secondary problem, of lesser importance, is that the cache never gets updated if the service worker responds with a cache copy. Of if it does, the console.log messages aren't getting executed or aren't producing output.

Third step - monitoring

To help with debugging, it occurred to me that it would make sense to produce a page that shows Service Worker and Cache status.


One thing I haven't explored yet is replacing the fetch call with one with different values for the request mode and credentials mode. I figured I would ask for guidance before proceeding down that path.

Once caching HTML is mastered, caching related artifacts like stylesheets and javascripts would be in order. An online fallfack approach would likely be the best match.

After that, the next order of business would be queuing of updates while offline. While in general, that would be a hard problem, in this case as user operations are limited by role and generaally to editing their own changes, it should be manageable.

Through cash app support, make your technical woes be gone

Do you want to know why your payment got canceled? If yes then our customer support service offers quick cash app support that is rendered by a technical team. Our techies will find out the reasons for the issues to troubleshoot it in a quick manner. Call now for availing of our service 1-844-409-2999.

Posted by john mark at

Solving the technical errors of cash app is easy with cash app number
Finding a way of rectification of all sorts of cash app glitches? In such a case, you have come to the right place where you’ll get immediate aid from techies just by ringing on the cash app number. No matter how far you’re, you can still get quick technical support from our technical team 1-833-554-7444.

Posted by john mark at

wow here i learn html coding thanks admin you help me thanks good work

Posted by Tamilgunfree at

It is very convenient to use Admission Essay Writing Service of Research Papers Writing Services company which is available at any time of the day of the week, month and year as it can assist you any time you require Custom College Papers Writing Services.

Posted by Term Paper Writing Services at

Sir, I am a big fan of you, I see your post daily and get very good information. I have written a post similar to your post, so if you like it, please approve it

Posted by shiva at

Criminology Papers Assignment Services online produces different assignments, including Criminology Research Paper Services, to help students deal with the Criminology Essay Writing Services challenges they face every day.

Posted by Criminology Research Paper Services at

Hope you will keep on offering good content like this more often. I feel more and more people should know about this. Also, I agree on most of the points you have made.
dubai exposition universelle 2020

Posted by Dubai Expo at

Its just amazing thing that I find in this post.

Posted by Jeff Garlin: Our Man in Chicago Cast at

This is a mistrust to which there is not a apart answer. Namely, it all depends on the penis enlargement selection that you choose. In requital for instance, no one can articulate.

Posted by Best Cooking Shows On Netflix at

Explore the list of all episodes of TV Serial Kumkum Bhagya online.
full HD Video Watch all episodes anytime, anywhere only on ZEE5

Kumkum Bhagya

Posted by Kumkum Bhagya at

Many unpleasant things square measure purported to stop a user from beginning their portable computer properly, or accessing Winchester drive knowledge commonly. Before continuing to any suggestions of a way to fix a dead portable computer or a way to recover knowledge from a dead portable computer Winchester drive while using your laptop if you lost your data and facing problem to recover the data. UAE data recovery one of the best option to find a good solution

Posted by zeshaan at

I recently found many useful information in your website especially this blog page.

Posted by keto burn xtreme at

I would recommend my profile  is important to me, I invite you to discuss this topic. std clinic singapore

Posted by seoamster at

very pretty post .. thanks for great help about html

Posted by Source at

Assignment papers help  is one of the largest cities in Australia. It is one of the most developed cities in the world too. Brisbane has many schools, colleges, and universities that have thousands of students enrolled in their courses to pursue their studies.

Posted by Academic Assignment Help at

Your texts on this subject are correct, see how I wrote  this site is really very good. White Noise Fan

Posted by seoamster at

May I simply say what a comfort to uncover somebody who genuinely understands what they are discussing over the internet. You definitely realize how to bring a problem to light and make it important. More people ought to look at this and understand this side of the story. I was surprised you’re not more popular given that you most certainly possess the gift.
GRE Test

Posted by gre practice questions at

Nice blog ! Get Marble Suppliers and
Granite Suppliers
near you.

Posted by Eonmarble at

Are you looking for Unmatched Legitimate Custom Research Paper Services? You don’t need to fail your Custom Research Paper Writing Services when you can utilize the best Dissertation Help Services or Affordable Custom Research Paper Services from the help of the online paper writers.

Posted by Buy Research Paper Online at

Yeh Rishta Kya Kehlata is indian star plus drama serial started on 2009.
Its cast involve naira and kartik they have good chemistry in love and other.

Yeh Rishta Kya Kehlata Hai

Posted by Yeh Rishta Kya Kehlata Hai at

Awesome information thanks for share this information sir">

Posted by Raghuver charan at

Awesome information thanks for share this information sir

Posted by Raghuveer Charan at

I’m still trying to learn how to read code, but it’s taking me a long time.

Hank - Fresh Home

Posted by Hank Gilbertson at

briefly discussed, appreciate your effort.

Posted by Rimsha at

At that point, you don’t need to go all over as a result of Aditi Gupta. Moreover, our Manali independent escorts are prepared for you for whenever to make your existence loaded with the new assistant. Furthermore, you can have perfect things and on the off chance that you are getting puzzled and attempt to be refresh.

Call Girl in Manali
Call Girls in Manali
Manali Escort
Manali Escorts

Posted by Mohini at

Here’s the thing. There is actually a plot device in the show explaining how Monica can afford to live in the apartment – it is a rent-controlled unit! 카지노사이트 예스카지노 더킹카지노 퍼스트카지노

Posted by 카지노사이트 at

Welcome to Amritsar Escorts which is an independent Amritsar Escort. All the Amritsar companions in the city are sophisticated, well educated, intelligent, and gorgeous as well as wise.
Follow Us:-

Amritsar Escorts
Amritsar Escorts Service
Amritsar Call Girls
Escorts Service in Amritsar
Call Girls In Amritsar

Posted by Amritsar Escorts at

Nice Post

Posted by Abhishek kumar at

Very interesting share that I need to show my colleagues at sex brandenburg

Posted by sexbrandenburg at

Watch Online Vidya Video Episode On Voot. Vidya Colors Tv Latest Hindi Drama Watch Full Episodes Vidya
online Today Drama.
Thanks for sharing such a nice stuff

Posted by Vidya Full Episode at

Hey This is great information, This is a educational website that you can add: Major kalshi classes India’s No. 1 Defence Coaching . Major kalshi classes pvt. ltd Founded in 2008, We have excelled in the preparation of defence examination like SSB, NDA, NAVY, Air Force, CAPF, AFCAT, TA, ICG etc. We are naw a centre of organized and focused learning which is pioneering in all formates of defence.

Posted by major kalshi at

nice information thank you so much

Posted by mkc publication at

On that website page, you’ll see your description, why not read through this. Cupom De Desconto Americanas

Posted by Cupom De Desconto Americanas at

On this subject internet page, you’ll see my best information, be sure to look over this level of detail. Cupom Lojas Americanas

Posted by Cupom Lojas Americanas at

Escorts Service in Aerocity
Call Girls in Haridwar
Russian escorts in Faridabad
Call Girls in Surat
Russian Call Girls in Agra
Call Girls in Aerocity

Posted by Juhi Sharma at

Escorts Service in Delhi
Escorts Service in Aerocity
Call Girls in Rishikesh
Call Girls in Faridabad
Escorts Service in Aerocity
Escorts Service in Faridabad

Posted by Juhi Sharma at

I recommend only good and reliable information, so see it: costco hours today

Posted by seomaster at

I am very happy when read this blog post because blog post written in good manner and write on good topic. Thanks for sharing valuable information.

Posted by CRM Software in Ahmedabad at

This is very interesting, but it is necessary to click on this link: voyance gratuite

Posted by seomaster at


Thank you for such informative article. I have gained a lot of information and knowledge. Keep posting amazing articles.

Posted by Shazib Farooq at

I like the these technical sites, but after a hard day I like to visit a transsexual for some fun.

Posted by TgirlPlaza at

What online slot centered on a royal couple would be worthy without a wild symbol? In Dragon and Phoenix, players will find the beautiful royal couple is the wild icon, substituting for all symbols in the game except for the scatter. 카지노사이트 예스카지노 더킹카지노 퍼스트카지노 카지노노하우 카지노사이트 카지노노하우 카지노사이트 온라인카지노 카지노게임사이트 예스카지노 더킹카지노 퍼스트카지노 바카라게임 블랙잭게임 룰렛게임 다이사이게임 카지노사이트 예스카지노 더킹카지노 퍼스트카지노 카지노노하우 카지노사이트 예스카지노 더킹카지노 퍼스트카지노 온라인카지노 카지노 예스카지노 더킹카지노 퍼스트카지노 바카라사이트 대박카지노 호게임 와와카지노 베스트카지노 카지노사이트 예스카지노 더킹카지노 퍼스트카지노 카지노사이트 예스카지노 더킹카지노 퍼스트카지노 카지노사이트 예스카지노 더킹카지노 퍼스트카지노

Posted by 카지노사이트 at

Are you looking for the best assignment writing services in USA.Then academic writing pro should be your best choice.They have the best assignment writing team who will write top quality assignments for you.We will always write unique and plagiarism free papers for you.

Posted by jerry bill at

Good work!

Seamless Eavestrough Saskatoon

Posted by Seamless Eavestrough Saskatoon at

In production process of a necklace for women some goldsmith use a variety of games and other fancy stone

Posted by necklace for women at

We MICROTEKNIK, leading manufacturer and exporters in the field of scientific laboratory equipments, Engineering educational equipments, hospital equipments , Waste management and Incinerators Since 1967 from Ambala (INDIA). Rich experience of over 5 decades in manufacturing with continuous improvements in producing world class quality products, supported by our in house R & D and users /customers feedback in achieving TEKNIK Brand as Import Substitution.

Posted by Sanitary Napkin Burner at

Remarkable ....
I was looking for CloudFlare workers, and this page appeared.
Really interesting and aveneristica, considering the results.
I apply your scripts with extreme joy ... and if possible I’ll let you know how it went.
Thank you so much.
[link]Moon Mkt[link]

Posted by Moon Mkt at

Yehh Jadu Hai Jinn Ka! is fantacy drama serial by indian tv channel
on Star Plus and directed by ram gopal verma and it is huge trp serial.

Posted by Yeh Jadu Hai Jinn Ka at

Pretty cool post. Lots of good information.

Click Here

Posted by Click Here at

We offers to the students by the help of its expert assignment writers. If you need any college level Assignment Help at prime quality with better work. Kindly visit All Assignment Help.

Masters Dissertation Help

Master Thesis Help

Posted by Masters Dissertation Help at

This is a very good application, I really like KineMaster 2020, I can edit my videos almost every day I open the kinemaster to edit / make other videos so hopefully the kinemaster won’t stop. Download Kinemater (Pro / Full / Mod) Apk latest version at

Posted by KineMater 2020 at

Add your comment