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

585
Views
404 error when trying to register serviceWorker

I get this error when trying to register the service worker:

Failed to register a ServiceWorker: A bad HTTP response code (404) was gwreceived when fetching the script.

I'm working with ionic and this is what I have in the app.js:

   if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js').then(function(registration) {
      console.log('ServiceWorker registration successful with scope: ', registration.scope);
    }).catch(function(err) {
      //registration failed :(
      console.log('ServiceWorker registration failed: ', err);
    });
  }else {
    console.log('No service-worker on this browser');
  }

On the directory I have the service-worker.js file right next to the app.js on the same folder.

Using latest chrome version on ubuntu desktop.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You mention that you have service-worker.js in the same directory as app.js, but the URL passed to .register() is relative to the HTML document's path. You need to make sure your service-worker.js file is in the same directory as the .html file corresponding to the page you're on.

over 4 years ago · Santiago Trujillo Report

0

The HTML document which is trying to register a service worker and SW.js should be in the same directory.

enter image description here

over 4 years ago · Santiago Trujillo Report

0

These are great replies and it helped with my confusion. I just wanted to add another thing just in case others are running into this problem and are confused as I was.

If you are using a bundler like Webpack, the path needs to be relative to the compiled version.

If your sw.js is in the /src folder but the compiled version of your html goes to a ./dist folder and your path to register the sw.js is "./sw.js", service worker is going to be searching in the dist folder for the sw.js file.

My solution to the problem above for Webpack is to use copy-webpack-plugin and send the file over from the src folder to the dist folder.

over 4 years ago · Santiago Trujillo Report
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!