Modern browsers provide an optimization feature for history navigation called the back/forward cache (bfcache). This enables an instant loading experience when users go back to a page they have already visited. Pages can be blocked from entering the bfcache or get evicted while in bfcache for different reasons, some required by a specification and some specific to browser implementations.
Remember, a Jedi can feel the Force flowing through him. I can’t get involved! I’ve got work to do! It’s not that I like the Empire, I hate it, but there’s nothing their pronunciation and their most common words today.
In our CSS file we’ll first need to create a family reference for the font files we’re loading via an @font-face declaration. (We recommend using a dedicated CSS file for loading our fonts.)
While the path to the font file must be precise, we can call our family name whatever we want. It’s not even necessary to have it in any way related to the actual name of the typeface—although keeping them consistent is recommended, of course. (Note that there must not be a space between url and the opening parenthesis—this is a common error.)
@font-face {
font-family: 'FAMILY_NAME';
src: url(FONT_FILE_NAME.woff2) format('woff2');
}
With the fundamentals of font loading covered, let’s explore some optional steps that can improve the user experience. It helps to understand a bit about the loading and rendering process; the basic flow of which goes something like this:
Optimizing lorem ipsum
- Browser requests a page
- Browser downloads HTML and linked CSS
- Browser parses HTML and CSS
- Browser initiates download of any linked CSS assets (like fonts)
- Browser now waits up to 3 seconds before starting to render the page while waiting for web fonts to download
- If the fonts arrive within 3 seconds, the page is rendered as it should be
- If the fonts have not fully loaded, the browser renders the page using fallback system fonts, then re-renders the page once the web fonts arrive
This comes in the form of a CSS descriptor called font-display. By providing a value of swap, we tell the browser to render the page right away with fallback fonts, and then redraw the page once the fonts have loaded.