next-pwa icon indicating copy to clipboard operation
next-pwa copied to clipboard

Generating sw.js and workbox-*.js in a subdirectory

Open ChrisAllday opened this issue 4 years ago • 6 comments

Hi, I have a question regarding placing the generated files in a specific directory.

Is it possible to specify a directory inside the public folder such as /public/pwa, as a location for the service worker and workbox files?

ChrisAllday avatar Oct 11 '21 06:10 ChrisAllday

I think so, use dest config option.

shadowwalker avatar Oct 14 '21 22:10 shadowwalker

@shadowwalker I did attempt that, however it still tries to load the sw.js from https://{url}/sw.js instead of checking https://{url}/pwa/sw.js.

Any idea how to change this as well?

ChrisAllday avatar Oct 15 '21 06:10 ChrisAllday

That's scope you should concern about. In most cases you want it to be loaded from the root path, only when you want the pwa in subpath like http://{url}/pwa/**/* and don't want the service worker to work for other paths like http://{url}/abc/**/*. So far I suggest you keep it in /public directly.

shadowwalker avatar Oct 15 '21 15:10 shadowwalker

If we want it to be inside sub-folder then how can we achieve that without disturbing the scope.

atuljain2995 avatar Feb 23 '22 16:02 atuljain2995

Also is there any way I can have custom workbox file name ?

atuljain2995 avatar Feb 23 '22 16:02 atuljain2995

@shadowwalker Is it possible to load the service-worker from a CDN instead of the root URL? Like https://mycdnurl.com/sw.js rather than https://mywebsiteurl.com/sw.js? (stackoverflow url)

Rishab1207 avatar Oct 12 '22 06:10 Rishab1207