Help - service workers and chestnut

Hello all.

I’m trying to add service-worker support to a site started with Chestnut. While I could use the existing single js output as the worker file, this is less then ideal as a) it would cause the service-worker process (which runs at arbitrary times on a user’s device) to be much larger then it needs to be, b) it would cause the rendering code, which is sent down the wire repeatedly, to contain unneeded service worker code, and c) it would require that the service worker’s update cycle be complected with the rendering code’s update cycle (rather then just caching the most recent changes). For the sake of simplicity and efficiency, setting up a separate cljsbuild profile and source directory seems like the better idea. I can cljsbuild from this new profile as you’d expect, and it uberjars fine.

Figwheel is another matter. The process for configuring the figwheel instance used by (go) is rather opaque, and I have been unable to figure out how to make it work with two cljsbuild profiles. (I tried changing the config in project.edn, using a seperate figwheel.edn file, and assoc’ing details onto various parts of the config record returned by (fw-config/fetch-config), but all without success.) I could do what the figwheel wiki says (https://github.com/bhauman/lein-figwheel/wiki/Using-Figwheel-with-Web-Workers), but that removes my ability to test the service worker against the site as a whole, which has been a key advantage of using chestnut so far.

My current solution is to advanced-compile the service worker so that its dependencies don’t conflict with figwheel, and run it there. This is as painful as you might imagine.

How do I set things up so that the figwheel component plays nice with service workers?

Thank you for your time,
-Alex

2 Likes

A lot of improvements have been made since this has been asked but I figure I’ll note here for anyone curious:

target :webworker has been added that allows for a stand-alone compilation script, with no advanced compile options for service workers.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.