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

Only download index + WASM when someone actually searches #102

Closed
itamarst opened this issue Dec 28, 2020 · 3 comments · Fixed by #131
Closed

Only download index + WASM when someone actually searches #102

itamarst opened this issue Dec 28, 2020 · 3 comments · Fixed by #131

Comments

@itamarst
Copy link

Hi,

Making some progress getting going, and it looks like WASM is 400KB, index for my site is 600KB (gzipped it's 200KB, so hopefully CDN will shrink it down to the latter). Even so, this is still a bunch of downloads for someone who isn't actively using search, and it seems like both get downloaded automatically even for users who aren't searching.

There's some work that could be done to shrink the WASM, I imagine, based on the tinysearch writeup (https://endler.dev/2019/tinysearch), but also it would be nice if download of WASM + .st file only happened if user clicks in the search box. At that point the cost of using Stork to most users is just the cost of the stork.js.

There are many places where a 1MB download is quite expensive (https://a4ai.org/new-mobile-broadband-pricing-data-2018), so it would be nice to minimize unnecessary downloading.

@fauno
Copy link

fauno commented Dec 29, 2020

Just to add that the wasm file can be compressed down to 93K (not sure if ls is using KB or KiB) using brotli -9. The site I tested has 600 articles and produced a 5.5M index, maybe it can be "sharded"? For instance having a small index that points to subindices, splitting them by first character.

Even though it's interesting to have the full index for offline searchs :)

@jameslittle230 jameslittle230 removed their assignment Dec 29, 2020
@jameslittle230
Copy link
Owner

I wonder if it's possible to delay the stork.register() call until someone hovers or focuses in the input. That should be possible from within user-space if you want to do this today, though I could also create a configuration option in the register method to delay any downloading until the user hovers or focuses.

This wouldn't affect the WASM download (I'd have to do that within Stork), but it would delay the index download, which might help.

Either way, this is definitely a good idea, and I'll look into this further.

Thanks!
James

@jameslittle230
Copy link
Owner

Hi all - I'm going to close this issue as solved when #131 is merged. #131 will add some new API methods to the Javascript stork object that lets you control when the WASM is downloaded, when the index is downloaded, and when the DOM elements are captured, all from within your JS surface. This would let you add a hover listener to some part of your page and hold off on making any network requests until that listener is triggered.

I'm hoping that this new API will get published in version 1.1.0.

Let me know if this doesn't work for you (though I think it will!) and we can continue the conversation.

Thanks,
James

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

Successfully merging a pull request may close this issue.

3 participants