The Best Methods for Loading Web Fonts Across Multiple Websites

best practices loading web fonts multiple websites
10 November 2024

Utilizing web fonts in the design and development of websites is one of the key factors that greatly impacts user experience. In fact, choosing the right font and properly loading it can lead to better web pages and appealing, readable displays. If you use a specific font across multiple websites, implementing an efficient loading strategy for these fonts is of greater significance.

There are various methods for loading fonts, but it’s better to lean towards using CDNs or content delivery networks. CDNs offer you the ability to host your resources, including fonts, on servers located in different parts of the world and provide users access from the nearest server. This practice helps reduce loading time.

Additionally, one of the other effective techniques is preloading fonts. By using the <link rel="preload"> tag, you can inform the browser that it needs to preload a specific font resource, and this task can expedite the loading process. This can help decrease initial loading time and improve user experience significantly.

Moreover, keep in mind that it's always better to serve fonts from more advanced formats such as WOFF2. These formats usually have smaller file sizes and are more optimal for the web.

Example Code for Preloading Web Fonts Using CDN


    <!-- Using the roboto font via Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">

    <!-- Preloading the roboto font -->
    <link rel="preload" href="https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Mu4mxK.woff2" as="font" type="font/woff2" crossorigin>
  

Description of the Code

<link href="..." rel="stylesheet">
This tag is responsible for loading the Roboto font from the Google Fonts service.
<link rel="preload"...>
This tag is used for preloading the font file that is about to be loaded.
href="..."
URL of the font file that should be preloaded.
as="font"
This defines the type of resource that is being preloaded as a font.
type="font/woff2"
This specifies the type of the font file being preloaded and indicates it's of the WOFF2 format.
crossorigin
This attribute is used for enabling cross-origin access to the preloaded resources in browsers.

FAQ

?

Why should we use preload for fonts?

?

How can we convert fonts?