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> => {
|
export const downloadGoogleFont = async (font: string): Promise<void> => {
|
||||||
const href = assembleFontLink(font)
|
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')
|
const link = document.createElement('link')
|
||||||
link.href = href
|
link.href = href
|
||||||
link.rel = 'stylesheet'
|
link.rel = 'stylesheet'
|
||||||
|
|
||||||
document.head.appendChild(link)
|
document.head.appendChild(link)
|
||||||
|
}
|
||||||
|
|
||||||
await new FontFaceObserver(font).load()
|
await new FontFaceObserver(font).load()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user