Skip to content

Commit 1f77577

Browse files
authoredJan 29, 2023
feat(theme): preconnect algolia when idle (#1851)
1 parent 010b3e5 commit 1f77577

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎src/client/theme-default/components/VPNavBarSearch.vue

+16
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ function poll() {
7878
}
7979
}, 16)
8080
}
81+
82+
onMounted(() => {
83+
const id = 'VPAlgoliaPreconnect'
84+
85+
const rIC = requestIdleCallback || setTimeout
86+
rIC(() => {
87+
if (!theme.value.algolia || document.head.querySelector(`#${id}`)) return
88+
89+
const preconnect = document.createElement('link')
90+
preconnect.id = id
91+
preconnect.rel = 'preconnect'
92+
preconnect.href = `https://${theme.value.algolia.appId}-dsn.algolia.net`
93+
preconnect.crossOrigin = ''
94+
document.head.appendChild(preconnect)
95+
})
96+
})
8197
</script>
8298

8399
<template>

0 commit comments

Comments
 (0)
Please sign in to comment.