Understanding the loading process of Google Fonts

I am curious about how Google Fonts determines which fonts to load. For instance, when I include this in my CSS:

@import '//fonts.googleapis.com/css?family=Roboto:300';

it generates a CSS file that is immediately interpreted (the loading of this resource even blocks the browser rendering as far as I know):

/* cyrillic-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(http://fonts.gstatic.com/s/roboto/v15/0eC6fl06luXEYWpBSJvXCIX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
  unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
/* cyrillic */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(http://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcYX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
// ...and some more

I always believed that when you specify a url(...) in CSS, the browser loads that resource immediately.

However, upon opening this pen http://codepen.io/anon/pen/EgkvEr and checking your network tab (maybe clear your cache), you can see that it only loads two resources: and then which represents the normal latin range (defined at the end of the loaded font css):

/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(http://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfZBw1xU1rKptJj_0jans920.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}

So, does the browser analyze the characters you use before loading the corresponding font? Or does it rely on your browser settings? I have not been able to find any documentation explaining this behavior (or perhaps I am using the wrong keywords). I suspect that the unicode-range: at the end of the CSS plays a role.

Answer №1

  1. A directive in the browser instructs it to fetch the CSS page from Google's server using the @import rule: . The browser immediately loads this page.

  2. Within that page, there are specified locations of font files using the url() function. However, these fonts are only downloaded by the browser when they are actually required. If a font is not utilized on any element, it will not be fetched.

The CSS attribute unicode-range at the end of the stylesheet likely plays a role in this behavior.

This is correct. The unicode-range property specifies the range of characters supported by the font (e.g., Cyrillic characters). If no characters within that range are present on the page, the associated fonts won't be retrieved.

For more information: https://en.wikipedia.org/wiki/Unicode_block

Answer №2

  1. Upon loading a webpage, the browser arranges the content and determines which font variations are needed to display the text.
  2. If a required font is not found locally, the browser then looks for it in external sources.
  3. In case the file is not present locally, the browser goes through different formats available:
    • If there is a specified format, the browser checks compatibility before downloading, moving on if necessary.
    • If no specific format is indicated, the browser proceeds with fetching the resource.

Google's guide to optimizing web fonts

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to adjust the size of a video thumbnail to fit within a

Currently, I am developing a system to remotely control home electrical devices via the web. However, I am facing an issue with fitting camera images properly within their container. https://i.sstatic.net/Yct2d.png How can I ensure that the video thumbna ...

Scrollbar becomes inactive following the loading of AJAX content

Having an issue with loading a div using Ajax. The div loads, however the scrollbar within it stops working afterwards. In Main.html, I load content from other HTML files like so: <div id="content1" > </div> The content is loaded as follows: ...

What are the steps to create custom pagination for tables?

Can you help me style a mui component in a similar way? https://i.sstatic.net/fxdvu.png I'm thinking of using the Pagination component and Select, but do you have any other suggestions? ...

Step by step guide on how to connect a stylesheet in CSS

Hey there, I recently attempted to link a style sheet in my HTML for the first time. Unfortunately, I encountered an issue where it didn't work. Here's the code I used: <link href="css/StyleSheet.css" rel="stylesheet" type="text/css" /> W ...

Generating tags dynamically with a function

Is there a way to showcase dynamic tags with proper line breaks in CSS? The responsive container needs to break gracefully: CSS: .tags { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; background-color: white; ...

Using Java code to show a tag on the screen

I attempted to display the label "until" when the user selects "range", but unfortunately, the label did not appear. Below are the codes I used. <td><select onchange="Show(this,'vin','until1');" <option v ...

Using infoWindows with multiple markers in Google Maps

i have developed a custom Google Maps application that pulls data from a CSV file. The functionality works well, but I am facing an issue with the infoWindow when looping through all the objects. It seems like the problem stems from the marker variable bei ...

Display an orange box (also known as a lightbox) when the page

My understanding of jquery and javascript is limited, so while I have come across solutions to similar problems, none have provided an explanation that allows me to adapt it to fit my version of a lightbox. I would like to use the orangebox (a jQuery plug ...

What is the best way to split a word within a list item in Bootstrap 4?

I am currently facing an issue with a list created using Bootstrap 4, where some items contain long text that is causing problems on small screen devices. I have attempted to use white-space:nowrap and the text-nowrap class, but neither solution has fixed ...

Deleting a row from a table using TypeScript in Angular

I am currently working on a task management application and I am facing an issue with deleting a row when clicking the delete button. Below is the table structure in my HTML: <table *ngFor="let todo of todos; let i = index;" class="todo ...

Centralized logo and slogan with Bootstrap 4 in navigation collapse

I am currently working on a Bootstrap 4 project that involves a navigation bar with a centered logo and tagline, along with links positioned to the left and right. While the setup is close to what I want, my ideal scenario would be for the logo to remain c ...

Having trouble adjusting the appearance of the dropdown menu in Angular Material's Select component

I've been attempting to adjust the style of the overlay panel within an Angular Material's MdSelect component in order to change the default max-width property of 280px. I have tried various methods, such as using '!important' to overr ...

Grow the Bootstrap column when hovered over (Similar to Netflix)

My grid view is structured as follows: jQuery(window).resize(function(evt) { jQuery(".grid-content > div > div > .channelImage").height(jQuery(".grid-content > div > ...

What is the best way to implement nested iterations in Jade?

ul li a(href='') menu1 li a(href='') menu2 ul li a(href='') sub-menu2 li a(href='') menu3 ul li a(href=&apos ...

Shifting hues with every upward and downward movement

I am experiencing a small issue with this JS code... -I have multiple divs that are changing automatically in rows as they move randomly... I want to change the color of the div moving up to green. And for the div moving down, I want to change the colo ...

Tips for ensuring my website displays consistently on different screen sizes

Is there a way to ensure that my website, informatiestuderen.nl, appears consistent on both small screens (such as phones) and large screens (like desktop computers)? Currently, my website is not functional on mobile devices. Take, for instance, carriere ...

The issue with the <Button> component not properly linking in next.js

Having trouble with a button wrapped inside a custom Navbar component. The code snippet in question is: <NavBtn> <Link href="/contact" passHref> <Button> Contact Me </Button> </Link> & ...

Ways to choose a distant relative in XML using XPath

To target all direct <p>...</p> elements inside a div, the selector would be div/p If I wish to select all second-level nested <p>...</p> tags within a div, I could use div/*/p Can a specific range be specified instead? div/descen ...

Incorporate text inside the border of a Material UI chip

https://i.stack.imgur.com/VATrD.png I'm looking to replicate this design using a pre-built Chip component from MaterialUI While the solution might involve Some Text using html and css, it still may not achieve an identical result. I've come acr ...

Floating a DIV causes it to shift down in a responsive layout at specific window sizes

My issue lies with a fluid layout that works well for the most part. However, at specific window widths, one of four floating div-elements unexpectedly shifts down. This inconsistency happens at nearly 20 different widths, differing by only one pixel. For ...