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

Dynamically load a consolidated file for Search related JavaScript to improve page load and reduce bandwidth. #1945

Closed
Jieiku opened this issue Jul 29, 2022 · 3 comments

Comments

@Jieiku
Copy link
Contributor

Jieiku commented Jul 29, 2022

Generally when you enable the search it will be the BULK of your sites download size.

For instance with abridge the download size is 328 KB, the search index is 253 KB or 77%, abridge theme demo only has 8 posts, a site with hundreds of posts will have a much larger index!

My idea to improve page load speed and reduce bandwidth usage is to dynamically load the search related JavaScript when a user clicks the search box. A user coming into your site from google results directly to their relevant page likely does not need your sites search so why serve them the file and waste the bandwidth?

I am currently working on this here: Jieiku/abridge#81

I have this mostly working, but I had to consolidate the search related files manually:

zola build
uglifyjs public/search_index.en.js public/elasticlunr.min.js public/search.js -o static/search_bundle.min.js -c -m

Then I use a 300 byte javascript file to load this bundle dynamically:

https://github.com/Jieiku/abridge/blob/4f7fc2aa2ad9b1f0bb4d44ed7a7f5161a3d9999c/static/search_facade.js

If I can work out the last couple issues with this solution, then I think the only thing left to do is to add a facility for zola to bundle the search related files together as one, similarly to how I do it with uglifyjs.

@Keats
Copy link
Collaborator

Keats commented Jul 30, 2022

That should be by a theme and not by Zola, I don't think it makes sense to start, I don't want to get into bundling right now.

@Jieiku
Copy link
Contributor Author

Jieiku commented Jul 31, 2022

I worked out the last couple issues with the dynamic loading of the search, it is live here: https://abridge.netlify.app/

I also updated the readme for abridge so that people know to build and bundle the index before deployment.

The Abridge demo handles this extra bundle step automatically with the included package.json and netlify.toml files.

https://github.com/Jieiku/abridge/blob/master/package.json

https://github.com/Jieiku/abridge/blob/master/netlify.toml

@Jieiku
Copy link
Contributor Author

Jieiku commented Sep 20, 2022

I will close this for now since it is a not gonna happen.

@Jieiku Jieiku closed this as completed Sep 20, 2022
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

2 participants