Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
Error in Service Worker: Cannot construct a Request with a Request object that has already been used

When the following service worker code runs I get a bunch of these errors:

serv-worker.js:38 Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Cannot construct a Request with a Request object that has already been used.

Question also asked here and unanswered: [https://stackoverflow.com/questions/55979921/error-request-object-that-has-already-been-used]

Appreciations for any help/explanation!

console.log('Start serv-worker.js');

const cacheName = '3.2121';

var urlsToCache = [
  'home.html',
  'home-js.js', 
  'web-bg.js', 
  'css/main.css',
  'css/edit-menus.css'
];

self.addEventListener('install', event => {
  console.log('Install event...', urlsToCache);
  event.waitUntil(
    caches.open(cacheName)
      .then(function(cache) {
        console.log('Opened cache', cacheName);
        return cache.addAll(urlsToCache);
      })
    );
});

//  Network first.
self.addEventListener('fetch', (event) => {
  // Check the cache first
  // If it's not found, send the request to the network
  // event.respondWith(
  //   caches.match(event.request).then(function (response) {
  //     return response || fetch(event.request).then(function (response) {
  //       return response;
  //     });
  //   })
  // );
  event.respondWith(async function() {
    try {
      console.log('aPull from network...', event.request);
      return await fetch(event.request);
    } catch (err) {
      console.log('aPull from cache...', event.request);
      return caches.match(event.request);
    }
  }());
});

self.addEventListener('message', function (event) {
  console.log('ServiceWorker cache version: ', cacheName, event);
  console.log('Received msg1: ', event.data);
  if (event.data.action === 'skipWaiting') {
    console.log('ccClearing cache: ', cacheName);
    // caches.delete('1.9rt1');     //  hardcode old one
    // caches.delete(cacheName);     //  actually removes cached versions
    caches.keys().then(function(names) {
      for (let name of names)
          caches.delete(name);
    });
    self.skipWaiting();
  }
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!