commit 07b1ee8588d71f9156a1ca75664dfa36f4b91cdd
parent c36369cf8195a68b874a6631de1afc3490f33593
Author: Amit Dutta <mail@amit.is-a.dev>
Date: Mon, 3 Aug 2026 23:40:35 +0530
Merge pull request #21 from notamitgamer/Patch
Patch for slow loading
Diffstat:
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts
@@ -14,6 +14,10 @@ const vitePressConfig = {
['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
['link', { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '' }],
['link', { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Lexend:wght@400;500;600;700&display=swap' }],
+
+ // Algolia Search warm-up
+ ['link', { rel: 'preconnect', href: 'https://5PYB0FB4RG-dsn.algolia.net', crossorigin: '' }],
+ ['link', { rel: 'preconnect', href: 'https://5PYB0FB4RG.algolia.net', crossorigin: '' }],
// SEO & Social Meta Tags
['meta', { name: 'algolia-site-verification', content: 'D732FF69A9237B42' }],
diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts
@@ -29,21 +29,29 @@ export default {
setup() {
onMounted(() => {
- // Small delay to ensure VitePress has rendered the navbar button
setTimeout(() => {
// Target the search/ask AI button
const searchBtn = document.querySelector('.DocSearch-Button');
if (!searchBtn) return;
- // When clicked, add the loading spinner
+ let prefetched = false;
+ const prefetchDocSearch = () => {
+ if (prefetched) return;
+ prefetched = true;
+ import('@docsearch/js').catch(() => {
+ prefetched = false;
+ });
+ };
+ searchBtn.addEventListener('mouseenter', prefetchDocSearch, { once: true });
+ searchBtn.addEventListener('focus', prefetchDocSearch, { once: true });
+ searchBtn.addEventListener('touchstart', prefetchDocSearch, { once: true, passive: true });
searchBtn.addEventListener('click', () => {
- // If the modal is already in the DOM, no need for the spinner
+ prefetchDocSearch();
if (!document.querySelector('.DocSearch-Container')) {
searchBtn.classList.add('is-loading');
}
});
- // Watch the page to see when the modal finishes downloading and appears
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.addedNodes.length) {
@@ -65,4 +73,4 @@ export default {
}, 500);
})
}
-} satisfies Theme-
\ No newline at end of file
+} satisfies Theme