Skip to content

Commit

Permalink
feat(theme): preconnect algolia when idle (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Jan 29, 2023
1 parent 010b3e5 commit 1f77577
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/client/theme-default/components/VPNavBarSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ function poll() {
}
}, 16)
}
onMounted(() => {
const id = 'VPAlgoliaPreconnect'
const rIC = 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>

<template>
Expand Down

0 comments on commit 1f77577

Please sign in to comment.