tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

force_refresh_worker.js (1358B)


      1 var name = "refresherCache";
      2 
      3 self.addEventListener("install", function (event) {
      4  event.waitUntil(
      5    Promise.all([
      6      caches.open(name),
      7      fetch("./sw_clients/refresher_cached.html"),
      8      fetch("./sw_clients/refresher_cached_compressed.html"),
      9    ]).then(function (results) {
     10      var cache = results[0];
     11      var response = results[1];
     12      var compressed = results[2];
     13      return Promise.all([
     14        cache.put("./sw_clients/refresher.html", response),
     15        cache.put("./sw_clients/refresher_compressed.html", compressed),
     16      ]);
     17    })
     18  );
     19 });
     20 
     21 self.addEventListener("fetch", function (event) {
     22  event.respondWith(
     23    caches
     24      .open(name)
     25      .then(function (cache) {
     26        return cache.match(event.request);
     27      })
     28      .then(function (response) {
     29        // If this is one of our primary cached responses, then the window
     30        // must have generated the request via a normal window reload.  That
     31        // should be detectable in the event.request.cache attribute.
     32        if (response && event.request.cache !== "no-cache") {
     33          dump(
     34            '### ### FetchEvent.request.cache is "' +
     35              event.request.cache +
     36              '" instead of expected "no-cache"\n'
     37          );
     38          return Response.error();
     39        }
     40        return response || fetch(event.request);
     41      })
     42  );
     43 });