dom-examples
dom-examples copied to clipboard
Question - Is there a reason for not allowing a server to start from the root directory?
Is there a reason for having the project setup in such a way that starting a web server from the project root causes an error in registering the service worker? It seems like a simpler way would be to register the service worker at the root of the project. For example:
// app.js
navigator.serviceWorker.register('/sw-test/sw.js', { scope: '/sw-test/' })`
// could be changed to
navigator.serviceWorker.register('/sw.js', { scope: '/' })
And then
// sw.js
return cache.addAll([
'/sw-test/',
'/sw-test/index.html',
'/sw-test/style.css',
'/sw-test/app.js',
'/sw-test/image-list.js',
'/sw-test/star-wars-logo.jpg',
'/sw-test/gallery/bountyHunters.jpg',
'/sw-test/gallery/myLittleVader.jpg',
'/sw-test/gallery/snowTroopers.jpg'
]);
// could be changed to
return cache.addAll([
'/',
'/index.html',
'/style.css',
'/app.js',
'/image-list.js',
'/star-wars-logo.jpg',
'/gallery/bountyHunters.jpg',
'/gallery/myLittleVader.jpg',
'/gallery/snowTroopers.jpg',
]);
With those changes I'm able to start a server from the project root directory and successfully register a service worker. But I don't know if maybe there's some implications to having it setup this way that I'm unaware of?
Hey @mattbrannon! This sounds like a reasonable suggestion. We are combining some of our repositories to enable us to triage pull requests and issues more effectively. Therefore, this specific repository will be merged into the more prominent dom-examples repository.
I will transfer this issue to the new repository for further discussion.
Hey! The SW project’s code has been refactored since you filed an issue. It’s now registering the SW a bit differently:
const registration = await navigator.serviceWorker.register(
'sw.js',
{
scope: './',
}
);
Do you think it fixes the issue?
Going to close this one for now. Thanks, all!