Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KingsleyO's avatar

Registering service worker

I am trying out service worker in my octobercms application. Following the guide on the workbox documentation i have in my layout file

<script>
// Check that service workers are supported
if ('serviceWorker' in navigator) {
  // Use the window load event to keep the page load performant
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/service-worker.js');
  });
}
</script>

and then i created service-worker.js file in the root directory of my app with this in it

console.log('Hello from service-worker.js');`

but i keep getting this error in console

A bad HTTP response code (404) was received when fetching the script. (index):1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.

googled to fixed the issue but things like writing the full directory like so

... navigator.serviceWorker.register('myoctober/service-worker.js'); did not work. In console under Appication->Service worker i also get the status of redundant.

0 likes
5 replies
Sinnbeck's avatar

Can you tell me where the file is located on your machine?

KingsleyO's avatar

This is how my folder structure looks like

-myoctober
 -.github(folder)
 -boostrap(folder)
 -config(folder)
 -modules(folder)
 -plugins(folder)
 -storage(folder)
 -tests(folder)
 -themes(folder)
 -vendor(folder)
 -.editorconfig
 -.gitattributes
 -.gitignore
 -htaccess
 -.travis.yml
 -artisan
 -CHANGELOG.md
 -composer.json
 -composer.lock
 -index.php
 -LICENSE
 -phpunit.xml
 -README.md
 -server.php
 -service-worker.js //my service worker file
KingsleyO's avatar
KingsleyO
OP
Best Answer
Level 1

nevermind. I have fixed it. I just had to whitelist the file in htaccess. Thanks for you time.

Please or to participate in this conversation.