Skip to content

Question: Integration of Service Workers #311

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

Closed
hannes-hochreiner opened this issue Jan 30, 2022 · 5 comments
Closed

Question: Integration of Service Workers #311

hannes-hochreiner opened this issue Jan 30, 2022 · 5 comments
Labels

Comments

@hannes-hochreiner
Copy link

I am working on a PWA with offline capability. I have not found a description on how to create a service worker file using trunk. Hence, I assume that this in currently not possible. I found PR 187, which is adding some PWA properties. However, creating a service worker file seems out of scope of that PR.

I can see three possible routes to take with this:

  1. Modify trunk to create the file (based on configuration setting)
  2. Use hooks to run an external program to create the file and modify index.html to call it (I am not sure hooks provide enough information to do that efficiently)
  3. Create a separate program to modify the files prepared by trunk (somewhat overlapping with option 2)

Any thoughts on the topic? Are you interested in integrating this kind of functionality into trunk?

@somehowchris
Copy link

Well I found that under assets you can actuall specify a worker, but doing that using the example I get the following:

gitpod /workspace/webpage (main) $ trunk build
Mar 28 07:51:16.677  INFO 📦 starting build
Mar 28 07:51:16.678  INFO spawning asset pipelines
Mar 28 07:51:16.909 ERROR ❌ error
error from HTML pipeline

Caused by:
    only one <link data-trunk rel="rust" .../> may be specified
Error: error from HTML pipeline

Caused by:
    only one <link data-trunk rel="rust" .../> may be specified

@hannes-hochreiner
Copy link
Author

Thank you for the hint. The example you are referring to is about "web workers" (i.e. a way to run code in a background thread). I was curious about "service workers" (i.e. a way to create an offline web app).

@somehowchris
Copy link

Well once added you can register your sw either in js or your first wasm binary, linking to that second generated binary. In the second binary cast your scope and use web_sys ServiceWorkerGlobalScope to do what you need

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Oct 22, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants