Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Ensure text remains visible during webfont load

Hi I'm facing this problem in google pagespeed I almost get my site speed to 100 the only thing remaining is Ensure text remains visible during webfont load

I'm already using font-display:swap; so why is this not fixing my problem.

here's my external font css

@font-face {
    font-display: swap;
      font-family: 'Miriam Libre';
      font-style: normal;
      font-weight: 400;
      src: local('Miriam Libre Regular'), local('MiriamLibre-Regular'), url(https://fonts.gstatic.com/s/miriamlibre/v5/DdTh798HsHwubBAqfkcBTL_fZ5P7.ttf) format('truetype');
    }
    @font-face {
    font-display: swap;
      font-family: 'Miriam Libre';
      font-style: normal;
      font-weight: 700;
      src: local('Miriam Libre Bold'), local('MiriamLibre-Bold'), url(https://fonts.gstatic.com/s/miriamlibre/v5/DdT-798HsHwubBAqfkcBTL_X3LbrQsq_.ttf) format('truetype');
    }

I generated this css using this commands

npx local-webfont https://fonts.googleapis.com/css?family=Miriam+Libre:400,700 /Users/admin/Documents/projects/font.css fallback

which I got from https://github.com/swissspidy/local-webfont

like image 871
leo Spacer Avatar asked Mar 31 '19 04:03

leo Spacer


People also ask

How do I stop showing invisible text?

Most browsers will hide texts until the font is loaded completely. This problem is known as flash of invisible text (FOIT). We can prevent it from happening by asking the browser to use the system font while the custom font is still being loaded. Once the font is loaded, it will replace the system font used earlier.

What is Webfont load?

The Web Font Loader is a JavaScript library that gives you more control over font loading than the Google Fonts API provides. The Web Font Loader also lets you use multiple web font providers. It was co-developed by Google and Typekit.

What is font display swap?

The font display strategy is defined by the user agent. block. Gives the font face a short block period and an infinite swap period. swap. Gives the font face an extremely small block period and an infinite swap period.


2 Answers

You are using google fonts. Its better to add &display=swap to fix the issue.

<link href="https://fonts.googleapis.com/css?family=Miriam+Libre:400,700&display=swap" rel="stylesheet">

Check this : https://www.infyways.com/fix-ensure-text-remains-visible-during-webfont-load/

like image 105
Abhilash Avatar answered Sep 18 '22 18:09

Abhilash


This property

font-display: swap;

saved my life. Full example is as following:

@font-face {
  font-family: 'Pacifico';
  font-display: swap;
}

And if you're using google fonts then use &display=swap at the end of href url, as following:

<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
like image 30
Shoaib Khalil Avatar answered Sep 22 '22 18:09

Shoaib Khalil