We take a little break from working on search to solve a little niggling issue.
“FOUT” being “Flash of Unstyled Text”. This is phenomenon where @font-face fonts take a little bit to load and thus you see the fallback font before the custom font. This is normally not a problem in Typekit. Nor is it really a problem in modern browsers these days (except IE 9). However, it is a problem for us because we’ve specifically chosen to load the Typekit JavaScript asynchronously.
Hope is not lost though, Typekit has this problem covered, we just need to do a smidge of work on our site. We put a new class name on the <html>
element called “wf-loading” (web font loading). Then in our CSS, we declare that any selector that uses a custom font is visibly hidden until that class name goes away. A little risky you might think, but if the font fails to load there is a timeout that removes the class anyway. This is just for fighting FOUT remember, just a little visual nicety.
We do all this by making a little Sass @mixin
called “preventFOUT” and @include
-ing it in our custom font stacks, which are also @mixin
s.
This works well for us now. Ultimately in this design we move over to HF&J fonts in which load directly via @font-face so we basically stop worrying about this.
hi chris! the link to paulirish.com doesn’t work because there’s a single quote at the end of it.
Thanks! Fixed.
I totally thought you were going to add
wf-loading & { visibility: hidden; }
to all your font-family mixins that have a web font. That way, anywhere you used a webfont, it automatically did the fight-the-FOUT stuff.On Typekit blog, it is also recommended to use .wf-inactive class as well to set up a fallback font-family stack if Typekit fails to load.