DEV Community

Do Cuong
Do Cuong

Posted on

01/12 - Intermediate CSS Concepts - More Text Styles (5)

01/12
TOP - Intermediate HTML and CSS: 22%.
Intermediate CSS Concepts - More Text Styles (5)

Currently reading : https://web.dev/articles/font-best-practices

Learn that @font-face is just used to declare the name of the font and where to look for it ( font-family, src ), not actually to download the font.

The browser will only download the font when it is applied in the styles.
For example:
@font-face {
font-family: TheFont;
src: url(path-to-the-font-file.woff) format("woff");
}
The above didn't get the font to be downloaded, only let the browser know that a font name TheFont is declared and where to look for it.

Only when the font-family get applied that the browser download the font, like this.
h1 {
font-family: TheFont; / TheFont font get downloaded and used for h1 /
}

Learn a bit about rel="preconnect".
preconnect, like it name suggested, hint for the browser to preemptively performing part of the handshake (DNS+TCP for HTTP, and DNS+TCP+TLS for HTTPS origins) to the target site for faster load.

Top comments (0)