Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple CDN example #35

Closed
josephrocca opened this issue Nov 5, 2023 · 5 comments
Closed

Simple CDN example #35

josephrocca opened this issue Nov 5, 2023 · 5 comments

Comments

@josephrocca
Copy link

It'd be great if there were a simple copy+paste CDN example in the readme. This would allow people to easily try it out in the browser, deno, etc. with a simple copy-paste code snippet. I tried this:

let webp = await import("https://cdn.jsdelivr.net/npm/@jsquash/webp@1.2.0/+esm");

and it loads, but when I try decoding:

await webp.decode(arrayBuffer)

it can't find the codec files. I saw this example in the readme:

import decode, { init as initWebpDecode } from '@jsquash/webp/decode';

initWebpDecode(WASM_MODULE); // The `WASM_MODULE` variable will need to be sourced by yourself and passed as an ArrayBuffer.
const image = await fetch('./image.webp').then(res => res.arrayBuffer()).then(decode);

But https://cdn.jsdelivr.net/npm/@jsquash/webp/decode@1.2.0/+esm doesn't exist, and @jsquash/webp only seems to export decode and encode functions - nothing else.

I also tried esm.sh: https://esm.sh/@jsquash/webp@1.2.0 but it isn't even able to load the module in the first place, for whatever reason.

@josephrocca
Copy link
Author

Ah, looks like unpkg is able to correctly find the codec files! This works:

let webp = await import(`https://unpkg.com/@jsquash/webp@1.2.0/index.js?module`);
let imageData = await webp.decode(arrayBuffer);

Could an example like that be added to the readme? Let me know if you want me to make the pull request.

@jamsinclair
Copy link
Owner

@josephrocca Thanks for the suggestion. I can look into adding an unpkg example 👍

Looks like there might be an issue with jsDelivr and wasm files. Is there a known fix for this? If not, I think it's best to stick with unpkg.

I will note that this package has been built specifically for the browser runtimes. I am unsure of Deno and Bun compatibility at this time and am in no rush to implement.

@josephrocca
Copy link
Author

josephrocca commented Nov 8, 2023

Thanks! A simple example like that in the readme would be really helpful helpful I think.

It doesn't currently work with Deno (just says "Decoding error"), but that's likely not your problem anyway, since Deno aims to be ~completely compatible with browsers (so long as e.g. DOM isn't needed), so it should eventually work as they continue to improve compatibility.

@jamsinclair
Copy link
Owner

@josephrocca Deno does seem to work with what I've played around with. I've added some examples in commit 60a959a.

Deno has yet to support the ImageData API (denoland/deno#19288) so you'll need to polyfill that.

Let me know if you're still encountering issues and I can take a look 👍

@josephrocca
Copy link
Author

Thanks, Jamie! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants