Closed srid closed 2 years ago
I believe Stork already supports this!
You can initialize Stork with a self-hosted WASM file. Then, any subsequent operations will use that WASM binary to operate.
You can read more about this on the Self-hosting documentation page.
Let me know if you have any more questions, or if that documentation page doesn't work for you.
Ah, nice! I should have read the documentation first :-) I'll try this out now ...
Okay, so it does work as far as the API goes - but it ends up loading both the local and remote wasm:
Could this be because register
is calling initialize()
(note: no args), which loads the default wasm URL (the second one in the screenshot above) in addition to the local one that is loaded when I call register
? The code I have:
window.addEventListener('load', function () {
stork.initialize(baseUrl + '_emanote-static/stork/stork.wasm');
stork.register(indexName, indexUrl);
});
Interesting! Maybe there's a bug.
If you just call initialize()
, does it load both WASM files?
What happens if you call the "split" API:
stork.initialize(yourUrl);
stork.downloadIndex(name, url, options);
stork.attach(name);
If you just call
initialize()
, does it load both WASM files?
If I do that, I see it loading the remote WASM twice:
The above behaviour was for this code:
window.addEventListener('load', function () {
stork.initialize(); // (baseUrl + '_emanote-static/stork/stork.wasm');
stork.register(indexName, indexUrl);
});
What happens if you call the "split" API:
It still loads both local and remove wasm:
window.addEventListener('load', function () {
stork.initialize(baseUrl + '_emanote-static/stork/stork.wasm');
// stork.register(indexName, indexUrl);
stork.downloadIndex(indexName, indexUrl, {});
stork.attach(indexName);
});
Hm - I'm having trouble reproducing it. When I call your original code in a Codepen, I'm only seeing one WASM blob load.
https://codepen.io/littleguy230/pen/poVpyQm
Are you sure this is the only time your code is interacting with Stork? No other calls to initialize()
anywhere else?
You are right; the issue is not with stork per se. It is to do with some other library I'm using, specifically, https://github.com/patrick-steele-idem/morphdom (used in route switch to replace HTML fast), which https://ema.srid.ca/ (used in Emanote) uses.
I confirmed it by checking the fully statically generated website, which does work per instructions at https://stork-search.net/docs/self-hosting
Sorry for the false alarm.
I'm guessing morphdom is double-loading stork.js
which somehow loads the default wasm when initialize/register is not called in time?
Problem: The
stork.js
generated in releases is hardcoded to usehttps://files.stork-search.net/releases/v1.5.0/stork.wasm
Desired behaviour: I'd like
stork.js
to use a localstork.wasm
file. i.e.:https://example.com/stork.js
should usehttps://example.com/stork.wasm
automatically.Implementation approach: I could pass the wasm URL (
/stork.wasm
for the above example) explicitly in theregister
function by having it take it as an argument;register
could, in turn, callinitialize
with that wasm URL, instead of invoking it with empty arguments.https://github.com/jameslittle230/stork/blob/8550f1fe13c334f16026d53886d3e17ae0193925/js/main.ts#L40-L45
as
initialize
already implements this:https://github.com/jameslittle230/stork/blob/8550f1fe13c334f16026d53886d3e17ae0193925/js/main.ts#L14-L15
Alternative approaches: Or can this desired behavior be achieved in a different way?