Skip to content

Instantly share code, notes, and snippets.

@Spike-Leung
Last active December 15, 2023 09:22
Show Gist options
  • Save Spike-Leung/eec9194504bb174513538ca277eaf5d4 to your computer and use it in GitHub Desktop.
Save Spike-Leung/eec9194504bb174513538ca277eaf5d4 to your computer and use it in GitHub Desktop.
Check if font has loaded
// see: https://www.zhangxinxu.com/wordpress/2022/04/js-font-face-load/
// see: https://developer.mozilla.org/en-US/docs/Web/API/FontFace/FontFace
import fontUrl from 'fonts/SourceHanSansSC-Regular.otf'
function check() {
try {
const font = new FontFace('SourceHanSansSC-Regular', `url(${fontUrl})`)
await font.load()
// load success
} catch (e) {
console.error(e)
// load failed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment