fix(theme-default): avoid preconnect without algolia (#1902)

pull/1903/head
Mr.Hope 3 years ago committed by GitHub
parent 43dddce813
commit 616fe5b636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,11 +29,29 @@ const buttonText = computed(
'Search' 'Search'
) )
const preconnect = () => {
const id = 'VPAlgoliaPreconnect'
const rIC = window.requestIdleCallback || setTimeout
rIC(() => {
if (!theme.value.algolia || document.head.querySelector(`#${id}`)) return
const preconnect = document.createElement('link')
preconnect.id = id
preconnect.rel = 'preconnect'
preconnect.href = `https://${theme.value.algolia.appId}-dsn.algolia.net`
preconnect.crossOrigin = ''
document.head.appendChild(preconnect)
})
}
onMounted(() => { onMounted(() => {
if (!theme.value.algolia) { if (!theme.value.algolia) {
return return
} }
preconnect()
// meta key detect (same logic as in @docsearch/js) // meta key detect (same logic as in @docsearch/js)
metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
? `'⌘'` ? `'⌘'`
@ -78,22 +96,6 @@ function poll() {
} }
}, 16) }, 16)
} }
onMounted(() => {
const id = 'VPAlgoliaPreconnect'
const rIC = window.requestIdleCallback || setTimeout
rIC(() => {
if (!theme.value.algolia || document.head.querySelector(`#${id}`)) return
const preconnect = document.createElement('link')
preconnect.id = id
preconnect.rel = 'preconnect'
preconnect.href = `https://${theme.value.algolia.appId}-dsn.algolia.net`
preconnect.crossOrigin = ''
document.head.appendChild(preconnect)
})
})
</script> </script>
<template> <template>

Loading…
Cancel
Save