Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is a fallback font downloaded?

If I set a Google font as a fallback font like so:

@font-face {
    font-family: 'GoogleFont';
    src: url('GoogleFont.ttf');
}

html, body {
    font-family: 'myMainFont', 'GoogleFont';
}

Will the Google font only be downloaded to the user's browser if the main font fails?

like image 766
mowgli Avatar asked Jul 28 '14 18:07

mowgli


People also ask

What is a fallback font and why do we need to use it?

A fallback font is a reserve typeface containing symbols for as many Unicode characters as possible. When a display system encounters a character that is not part of the repertoire of any of the other available fonts, a symbol from a fallback font is used instead.

What is font-display fallback?

fallback. Gives the font face an extremely small block period and a short swap period. optional. Gives the font face an extremely small block period and no swap period.

Why do we use fallback fonts in CSS?

CSS font Fallbacks provide a backup for the fonts i.e. if one font doesn't work properly then the browser will try the other one. For good coding practice write a generic font family at the end of the list and choose the font fallback within the same font family.


1 Answers

EDIT

According to the spec, @font-face fonts should only be downloaded when they are required to render the document: http://www.w3.org/TR/css3-fonts/#font-face-loading

The @font-face rule is designed to allow lazy loading of font resources that are only downloaded when used within a document. A stylesheet can include @font-face rules for a library of fonts of which only a select set are used; user agents must only download those fonts that are referred to within the style rules applicable to a given page. User agents that download all fonts defined in @font-face rules without considering whether those fonts are in fact used within a page are considered non-conformant. In cases where a font might be downloaded in character fallback cases, user agents may download a font if it's contained within the computed value of ‘font-family’ for a given text run.

NOTE: At the time of writing this answer, different versions of browsers on various systems seem to implement this behaviour wildly differently. All we can do is hope that they will eventually conform to the spec.

Chrome and Firefox (testing others in progress) will only download fonts that are required to render the content that is being displayed, regardless as to what's been specified via @font-face. More importantly, if you specify an @font-face font and then don't use it, e.g.

.css-rule { font-family: Helvetica,'My at-font-face-font',sans-serif; }

Then your custom font face will not be downloaded because it does not need to be.

To examine what fonts are being download and when, open up your network tab during a page load.

EDIT

It appears that the behavior of browsers varies greatly on this issue and I encourage more looking into your individual circumstances.

I can guarantee one thing, however, and that is not all fonts are downloaded all the time in all browsers, just because you've declared them via @font-face.

like image 52
Adam Avatar answered Sep 19 '22 12:09

Adam