1

I made a simple AngularJS to-do app and used sw-toolbox. It is working fine on my localhost but when I am using it on gh-pages, few 404 errors are thrown on console and service worker is also showing 404 error while fetching scripts.

DEMO

CODE

2 Answers2

0

The thrown error, TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script., tells us that the SW script itself was never found. The browser tried to fetch the script but was not able to since 404 was returned.

Very simple mistake. Your app tries to register the sw.js file from https://viveksharma619.github.io/sw.js while it's actually located in https://viveksharma619.github.io/PWA_simple_to_do/sw.js

The evil here is /sw.js - on your computer you were probably running the site in localhost:8080 when /sw.js was the real location but now the app lives inside PWA_simple_to_do folder and the sw.js script should be pointed to by either "sw.js" (current folder) or /PWA_simple_to_do/sw.js

pate
  • 4,937
  • 1
  • 19
  • 25
  • I have changed the location it was pointing but now the error is coming from sw.js, it is unable to find sw-toolbox.js from node_modules. I have tried using both /PWA_simple_to_do/node_modules/... as well as /node_modules/... in both cases, it is showing **Failed to load resource: net::ERR_INVALID_RESPONSE** – Vivek Sharma Mar 05 '17 at 16:07
  • Hmm. Neither of these two seem to work: https://viveksharma619.github.io/node_modules/sw-toolbox/sw-toolbox.js https://viveksharma619.github.io/PWA_simple_to_do/node_modules/sw-toolbox/sw-toolbox.js I suggest that you develop a working version locally and after that deploy it to Github pages. – pate Mar 06 '17 at 18:58
0

Since gh pages are hosted using jekyll, jekyll version 3.3 by default ignores node_modules and vendor files. Hence, you won't be getting them when fetched from gh-pages. It will instead log "Failed to load resource" for sw-toolbox.js.

Your can bypass this by adding a simple .nojekyll file to the root of your github repository and your code will work just fine.