Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable service-worker.js selectively on page_config #2367

Closed
acoyfellow opened this issue Sep 4, 2021 · 4 comments
Closed

Disable service-worker.js selectively on page_config #2367

acoyfellow opened this issue Sep 4, 2021 · 4 comments
Labels
service worker Stuff related to service workers

Comments

@acoyfellow
Copy link

acoyfellow commented Sep 4, 2021

Describe the problem

I've got a use case where I'd like to disable the service-worker.js on only specific page levels. I want to exclude it on only 2 routes in my app.

Describe the proposed solution

<script context="module">
  export const service_worker = false;
</script>

Alternatives considered

Having dual svelte-kit apps, both sharing about 99% of the codebase, but one does not have a service-worker.js

Importance

would make my life easier

Additional Information

I've not yet fully understood how to submit the pull request (my understanding of the svelte-kit internals are limited), but i was able to simply modify ...node_modules/@sveltejs/kit/dist/ssr.js: (i find it here)

find:
if (options.service_worker) {

replace with:
if (options.service_worker && !!page_config.service_worker) {

To enable

<script context="module">
  export const service_worker = false;
</script>

And we could just add one more section to the page-config options inside of the docs.

** edit: my proposed solution does not do what I expected it to - I obviously am not understanding the svelte-kit internals enough (yet)

@acoyfellow acoyfellow changed the title Disable service_worker.js selectively on page_config Disable service-worker.js selectively on page_config Sep 4, 2021
@benmccann benmccann added the service worker Stuff related to service workers label Sep 4, 2021
@benmccann
Copy link
Member

Would #2281 help you? You could disable the automatic service worker registration and then register yourself. I'd prefer that to adding more options

@acoyfellow
Copy link
Author

Yes, I think so, if i'm understanding that pull correctly:

I'd be able to set serviceWorker.register to false in my config, then just opt-in each page that i do want it on

@acoyfellow
Copy link
Author

Looks like #2281 might be ready for approval.. I'm still looking for a solution here

@benmccann
Copy link
Member

#2988 has been merged which adds an option to disable the existing service worker registration, so I think you could now add your own to address this and I'll go ahead and close this. Let me know if there's something that would still be required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service worker Stuff related to service workers
Projects
None yet
Development

No branches or pull requests

2 participants