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

Export an init function #1

Open
ghost opened this issue May 2, 2022 · 5 comments
Open

Export an init function #1

ghost opened this issue May 2, 2022 · 5 comments

Comments

@ghost
Copy link

ghost commented May 2, 2022

In order to allow pre-emptive initialisation of the wasm module to prevent an unwanted lag on the first request.

Current workaround is calling new HtmlRewriter() and a delay() function, but this functionality should ideally be exported from the library.

@ghost
Copy link
Author

ghost commented May 2, 2022

A better workaround for the time being:

// execute at start of module
const res = new HTMLRewriter().transform(new Response("Initialized wasm"));
console.log(await res.text());

@qwtel
Copy link
Member

qwtel commented May 3, 2022

new HTMLRewriter() should be all that is required to trigger WASM initialization.

The code this module is based on triggered the WASM initialization lazily as part of transform, but I moved it inside the constructor as I thought it was more appropriate for a polyfill.

@ghost
Copy link
Author

ghost commented May 3, 2022

What I mean to say is there is a delay the first time you use it while it is loading the wasm. It would be good if you could load the wasm when your module starts (when using this in deno for example) to avoid the delay on first usage.

@qwtel
Copy link
Member

qwtel commented May 3, 2022

Can you confirm that calling new HTMLRewriter() (without transform etc.) at the start of the module is not enough to trigger WASM load/initialisation?

@ghost
Copy link
Author

ghost commented May 3, 2022

It works but feels hacky/like a workaround. A more explicit function would be preferable

Edit: Only calling the constructor is enough to trigger it but it is not possible to await the initialisation which defeats the point.

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

No branches or pull requests

1 participant