perf: ️ google font

only create link if the link doesn't exist
This commit is contained in:
Julien Calixte
2024-04-06 15:40:32 +02:00
parent 2cb7048170
commit 78c52b0cb1

View File

@@ -3,11 +3,18 @@ import FontFaceObserver from 'fontfaceobserver'
export const downloadGoogleFont = async (font: string): Promise<void> => { export const downloadGoogleFont = async (font: string): Promise<void> => {
const href = assembleFontLink(font) const href = assembleFontLink(font)
const link = document.createElement('link') // check if the href already exists
link.href = href const existingLink = document.querySelector(`link[href="${href}"]`)
link.rel = 'stylesheet'
document.head.appendChild(link) console.log({ existingLink })
if (!existingLink) {
const link = document.createElement('link')
link.href = href
link.rel = 'stylesheet'
document.head.appendChild(link)
}
await new FontFaceObserver(font).load() await new FontFaceObserver(font).load()