Reputation: 529
What I've got is a font-family CSS declaration to use a stylised web font first, and fall back to system fonts. This works fine, but my web font is huge ~15MB (Chinese font) and even hosting this on CDN it takes over 5s to load.
The problem with this is that browsers handle the display differently. I think Firefox has the preferred way, which is to use whichever font is available first (system font) and progressively display in the web font when it is ready (loaded).
However, Chrome just tries to use the web font first (as this is listed first in the font-family) and just displays a blank space until the font is ready to render the text.
Is there a way to make Chrome behave the same as Firefox?
EDIT: Add font-family declaration.
font-family: "Noto Sans CJK TC", "Microsoft Yahei", "微软雅黑",
SimHei, "黑体", STHeiti, "华文黑体", sans-serif;
Upvotes: 3
Views: 10327
Reputation: 1383
the simple way to achieve this to add
@font-face {
font-display: swap;
}
for more information https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display
Upvotes: 2
Reputation: 529
After reading all the comments, I now have an acceptable solution to progressively loading web fonts.
font-family
CSS definitions initially to use web safe fonts.@font-face
definitions as normal and use a font loader with event handling to progressively render fonts (https://github.com/bramstein/fontfaceobserver).There is a slight "pop" when newly loaded font's replace the web safe ones, but at least there is no FOIT (flash of invisible text).
https://www.filamentgroup.com/lab/font-events.html has a good guide on using FontFaceObserver, but couldn't get it to work with their example code. Instead, I used the reference code from the GitHub repo - although I think their wording is wrong/misleading. You should use fontfaceobserver.standalone.js
if you don't have a Promise polyfill already implemented.
Upvotes: 3