Fork me on GitHub

So it looks like the rules around js/SharedArrayBuffer are starting to settle down. You have to add COOP/COEP headers to your server. So I updated my tau.alpha lib and got the old demo working on netlify. The whole lib needs a re-write, and decomposition into smaller libs, one of which is a small lib that can spawn workers programmatically, which reminded me of this response I gave to a question about on Clojureverse. For tau.alpha, I got it working in both simple and advanced compile mode For a rewrite though, I'd like build a thing that works in all compile modes, and works for vanilla, figwheel and shadow-cljs build systems. I think leaning into CLJS modules/code splits might be the best way to make a thing that can be used from all different build systems and compile modes. I wanted to check in here though and see if I could get any pointers. Any gotchas to look out for? Any shortest-paths I haven't considered? Any work desired for addition to CLJS core? On that note, I'm thinking about making a PR to allow vanilla CLJS to take a map of optional headers in the compiler options / build.edn, so you can enable COOP/COEP for enabling development with SABs - in figwheel, I'm using a custom ring.handler. Let me know if anything comes to mind.


Removing all the tau stuff, that spawn fn boils down to:

(defn create-worker-body [require-ns]
  (let [multi-loader
        (str "CLOSURE_BASE_PATH = '" goog/basePath "';\n"
             "this.CLOSURE_IMPORT_SCRIPT = (function(global) {\n"
             "    return function(src) {\n"
             "        global['importScripts'](src);\n"
             "        return true;\n"
             "    };\n"
             "if(typeof goog == 'undefined') importScripts(CLOSURE_BASE_PATH + 'base.js');\n"
             "importScripts('" (str goog/basePath "../cljs_deps.js") "');\n"
             "goog.require('" require-ns "');\n")
          "importScripts('" (last (scripts-src)) "');\n")]
    (if (empty? goog/basePath) single-loader multi-loader)))
Wondering if there's a better, more resilient way to go about that, perhaps using code-splitting modules, that'll work in both advanced compiled mode and simple (or none), across all build tools.


And that was written over 4 years ago, so there might be a better way these days