CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.63k stars 119 forks source link

Fallback for when WebAssembly is not available #359

Open Seirdy opened 1 year ago

Seirdy commented 1 year ago

WebAssembly is not available when browsers disable JIT compilation:

I'm sure more examples exist. Some of these, such as iOS Lockdown and Edge's Enhanced Security, are relatively recent developments, so it's not unreasonable to assume that the popularity of JIT-toggling will increase with time.

A good approach would be to have an asm.js-based fallback. That's the approach used by CryptPad, and it has good results. Some polyfills allow transpiling WebAssembly to asm.js with usable performance.

bglw commented 1 year ago

This is a good idea, and the concept of transpiling the WebAssembly is especially great as it reduces any maintenance burden in having both implementations. I haven't experimented with any transpilers, but Pagefind's WebAssembly is intentionally simple and small, so if anything would work through that process it would be this.

I'm unlikely to have the time to tackle this in the medium-term, but I'm open to someone contributing this as a feature. Ping me in this thread if anybody wants to spitball what might be needed for them to implement this 🙂

easrng commented 10 months ago

polywasm works fine with pagefind. tl;dr

self.WebAssembly = self.WebAssembly || (await import("https://unpkg.com/polywasm@0.1.4/index.min.js")).WebAssembly
demosthenez commented 9 months ago

I just ran into this issue with chromite and vanadium. I posted about it here but will remove it now.

bglw commented 9 months ago

polywasm works fine with pagefind.

Impressive! Thanks for the pointer. I'll take it for a spin and then look at adding this as an official fallback.