perf: ⚡️ google font
only create link if the link doesn't exist
This commit is contained in:
@@ -3,11 +3,18 @@ import FontFaceObserver from 'fontfaceobserver'
|
||||
export const downloadGoogleFont = async (font: string): Promise<void> => {
|
||||
const href = assembleFontLink(font)
|
||||
|
||||
// check if the href already exists
|
||||
const existingLink = document.querySelector(`link[href="${href}"]`)
|
||||
|
||||
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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user