Skip to content

Commit 616fe5b

Browse files
authored
fix(theme-default): avoid preconnect without algolia (#1902)
1 parent 43dddce commit 616fe5b

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

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

+18-16
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,28 @@ const buttonText = computed(
2929
'Search'
3030
)
3131
32+
const preconnect = () => {
33+
const id = 'VPAlgoliaPreconnect'
34+
35+
const rIC = window.requestIdleCallback || setTimeout
36+
rIC(() => {
37+
if (!theme.value.algolia || document.head.querySelector(`#${id}`)) return
38+
39+
const preconnect = document.createElement('link')
40+
preconnect.id = id
41+
preconnect.rel = 'preconnect'
42+
preconnect.href = `https://${theme.value.algolia.appId}-dsn.algolia.net`
43+
preconnect.crossOrigin = ''
44+
document.head.appendChild(preconnect)
45+
})
46+
}
47+
3248
onMounted(() => {
3349
if (!theme.value.algolia) {
3450
return
3551
}
52+
53+
preconnect()
3654
3755
// meta key detect (same logic as in @docsearch/js)
3856
metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
@@ -78,22 +96,6 @@ function poll() {
7896
}
7997
}, 16)
8098
}
81-
82-
onMounted(() => {
83-
const id = 'VPAlgoliaPreconnect'
84-
85-
const rIC = window.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-
})
9799
</script>
98100

99101
<template>

0 commit comments

Comments
 (0)