Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Flash of Unstyled Text (FOUT) even with Web Font Loader?

Tags:

html

css

webfonts

I'm using a custom font which is large ~100kb. As you can imagine, the browser text is flashing from invisible to visible text. I therefore started using the webfontloader: https://github.com/typekit/webfontloader

However, even with this fontloader, the text still flashes. The page loads with the default font, and then once the webfontloader says the font has loaded, the CSS is triggered to use the loaded font however, it still results in the text flashing... See the codepen for example. Anytime you hard-refresh and the font needs to load, the text is flashing.

https://codepen.io/anon/pen/LQGrpL

WebFont.load({
  custom: {
    families: ['Inter UI'],
    urls: ['https://rsms.me/inter/inter-ui.css']
  }
});
body,
button {
  font-weight: 400;
  font-size: 14px;
  font-family: sans-serif;
  font-style:  normal;
}

.wf-active body,
.wf-active button {
  font-weight: 400;
  font-size: 14px;
  font-family: 'Inter UI';
  font-style:  normal;
}
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
<h1>Hello World</h1>

<p>Good day to you...</p>

<button>Thank you</button>

Is there anything I can do to avoid this flashing? It's a horrible user experience.

like image 626
AnApprentice Avatar asked Feb 02 '18 22:02

AnApprentice


People also ask

How do you fix Fout?

The best way to deal with FOUT is to make the transition between the fallback font and web font smooth. To achieve that we need to: Choose a suitable fallback system font that matches the asynchronously loaded font as closely as possible. Adjust the font styles ( font-size , line-height , letter-spacing , etc.)

How do you fix ensure text remains visible during Webfont load?

To fix the “ensure text remains visible during webfont” warning, you need to use the font-display: swap declaration on the web font. This simple attribute in your font's CSS fixes the invisible text issue on WordPress: it displays the text during web fonts loads.


1 Answers

Consider experimenting with the Web Font Loader library which provides an event system that allows you to control the appearance of your page dynamically as fonts are loaded.

Here

like image 163
Wael Assaf Avatar answered Sep 16 '22 13:09

Wael Assaf