jamsinclair / jSquash

Browser & Web Worker focussed image codec wasm bundles derived from the Squoosh App.
Apache License 2.0
250 stars 19 forks source link

background execution? #58

Closed turbobuilt closed 5 months ago

turbobuilt commented 5 months ago

Describe the bug My page freezes when this is going. Is there a way to make this run on a background thread? I'm using the vite version.

Edit: just switched to the regular, and it still freezes (the spinner stops spinning) while converting

To Reproduce Steps to reproduce the behavior: just use it as usual

jamsinclair commented 5 months ago

Hi @turbobuilt,

That is to be expected as the code will be running on the main thread and will overwhelm the event loop and halt everything until it completes.

We can use WebWorkers to offload that work.

I've created an example app showing how to use WebWorkers at https://github.com/jamsinclair/jSquash/tree/main/examples/web-workers. You can see how the work is split between the following two files and how messages are passed between the workers:

If you're using Vite, please also note the Vite config required for workers.

I hope that helps!

turbobuilt commented 5 months ago

Whoops, my bad!