hi there
I’ve been on a bit of a journey. I have a performance problem that I think would be in a better spot if I could do some work in a Web Worker (do some work off the main thread). Of course I could write the Web Worker in JavaScript but what would be the fun of that.
I found this excellent article on putting Elm in a web worker.
But for my purposes I would prefer to have an “inline” web worker. (At least I think I would). So I found this article plus some Stack overflow answers of various ways to do that.
The thing to do seems to be to put the Javascript for the Web Worker into a Blob
.
I’ve hacked together a little script that compiles the Elm, puts it the Javascript glue code it’s needs. And then… well… I seem to have gotten my self into “escape hell”.
I need to get the Elm code into a Javascript string. I tried putting it in a back-tick string, but I had to escape the back-tick in the generated javascript code. Now that code is failing because… the generated javascript code contains some regex stuff with escape characters in it, and I tried a couple different things but once I start dealing with multiple levels of character escaping… well… I’m just throwing spaghetti at the wall.
Has anyone out there done anything like this? Is there maybe a tool out there that will put javascript (unmolested) into a Blob
? Maybe there’s a tool that will turn the Elm javascript into some sort of encoded format where escape characters are no longer an issue?
I will keep trying things, and if I find an answer I will be sure to post it.