Is there a chance that unused fonts included in @font-face are still being requested by browsers?

Curiosity

Do browsers fetch and download all the files specified in @font-face declarations or do they grab only the ones referenced in stylesheets?

For Instance

Imagine I have these 3 @font-face declarations:

@font-face {
  font-family: 'A';
  src: url('http://fonts.com/font-a.woff2') format('woff2');
}

@font-face {
  font-family: 'B';
  src: url('http://fonts.com/font-b.woff2') format('woff2');
}

@font-face {
  font-family: 'C';
  src: url('http://fonts.com/font-c.woff2') format('woff2');
}

And then my styles are as follows:

body {
  font-family: 'A';
}

h1 {
  font-family: 'B';
}

Does the browser fetch font C, even though it is not referenced in the stylesheet? Is there a definitive answer within the specification?

Answer №1

Absolutely - some outdated browsers, like IE8 and older, still request unused fonts.

However, the majority of modern browsers nowadays do not make extra requests for unused imports. Read more here

If you're looking to use custom fonts like Lato, Roboto, and Raleway, it's best to import them from Google Fonts.

@font-face {
 font-family: 'A';
 src: url('https://fonts.googleapis.com/css?family=Lato');
}

@font-face {
  font-family: 'B';
  src: url('https://fonts.googleapis.com/css?family=Roboto');
}

@font-face {
  font-family: 'C';
  src: url('https://fonts.googleapis.com/css?family=Raleway');
}

body {
  font-family: 'A';
}

h1 {
  font-family: 'B';
}

When using the following HTML markup:

<body>
  <h1>Lorem ipsum</h1>
  <p>Lorem ipsum dolar sit amet</p>
</body>

You can view the browser requests in the developer tool, such as in Google Chrome, by pressing F12 and opening the network tab.

https://i.sstatic.net/MRlGc.png

Note that only Roboto and Lato were requested, even though Raleway was imported in the CSS file.

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

Can the appearance of the Chrome browser be altered to resemble a printed page?

Simply put, I'm tackling a massive project right now. While my print.css is functioning perfectly, the task of constantly previewing the print page has become incredibly frustrating. What's more, it's impossible to inspect the page effectiv ...

Making an element transparent in CSS without affecting the text within it

Recently, I created a menu block element and decided to apply an opacity of 0.4/40 to it. However, I encountered an issue where the text within the menu block was also affected by the opacity. My aim is to have the opacity only impact the menu block itsel ...

Why does the container overflow when the child is floated in CSS?

Can you explain why a parent div element stops adjusting its height when its child is floated? Here is the HTML snippet: <!DOCTYPE html> <html> <head> <title>test</title> <link rel="stylesheet" type="text/css" href="in ...

Although HTML and CSS files may be similar, the way in which styles are implemented can vary greatly from one

Working on a project locally, I noticed different styling on one element between two repositories. Despite the HTML, CSS, and JS files being identical according to WinMerge, there's an inconsistency with the bootstrap class card-img-overlay. The issue ...

The oversized monitor is cut off halfway due to postcss-pxtorem

When designing a screen with dimensions of 3840 x 2160, the initial draft was created with 1920 x 1080. I utilized postcss-pxtorem with a "rootValue" set to 192 for responsive scaling. The zoom is normal and functional on screens below 1920 pixels wide. ...

Appearance with grey background color instead of transparency

After attempting to remove the background-color attribute, I noticed that the background remains a shade of grey instead of becoming transparent. Here is the code snippet: CSS: #contact-form button[type="submit"] { position: absolute; width: 100 ...

jQuery will envelop the HTML elements in an inconsequential div

Imagine a website that is visually complex, with various styles and images positioned in different ways. What if we wanted to add a small overlay icon above each image? At first, the solution might seem simple - just use absolute positioning for a span el ...

What is the best way to have a div created by JavaScript automatically expand to cover the entire screen after clicking on a dynamically generated table cell?

A unique interactive game inspired by Jeopardy is in the works. By clicking on a specific element within the game board, players can reveal questions fetched from the Jeopardy API. These questions are then presented elegantly within a dynamically created d ...

What steps should I take to align my NAV next to each other on the top right of the page?

Can someone help me align my NAV elements next to each other? I am having trouble figuring out how to do it currently. #menu { display: inline-block; position: absolute; right:0; top: 10%; } <ul id="menu"> <nav> ...

The table's pagination displays above, thanks to Tailwindcss

I'm facing an issue where the pagination is showing up above the table, but I was expecting it to be displayed after the table. It would be ideal if the pagination appeared right after the table when adding multiple rows. Check this link for more inf ...

Issue with displaying elements at intended layering order when parent element has fixed positioning

My web app features both upper and lower elements (div) with a position: fixed. Each element has child popups also with position: fixed. Even though I want to position the popup above its parent element, using z-index doesn't work due to inheritance ...

Using jQuery to animate a div when clicked by the mouse

Here's the scenario: I have 3 block elements arranged in a specific order: Image Hidden Text Block (.hidden) Footer Block (.blockimage) When the page loads, the image is displayed over the hidden text block (which contains further infor ...

Hovering over a div element will trigger a change in another embedded div

My HTML Code: <div id="menu"> <div class="arrows"> <div class="arrow-down"></div> </div> <div class="buttons"> <button class="home">Home</button> ...

I am trying to set the text direction to RTL for the window.getSelection value. However, I'm having trouble figuring out how to remove getSelection from the current value

var userInput = document.getElementById('inputText').value; function insertAtCursor() { if (window.getSelection) { selectedText = window.getSelection(); ...

Tips for removing CSS and Javascript code from a website's source code

After implementing the Slicknav Menu plugin on my website, I noticed that a portion of the plugin's CSS and script code is visible when inspecting the source code of the main page: <head> ... <style id='slicknavcss-inline-css&apo ...

Load website once AJAX has finished

Currently, I am using an ajax call to retrieve the color scheme of my website from the database due to having multiple clients with different schemes. My goal is to ensure that the page only loads after the ajax call has completed. Despite an expected dela ...

The lack of vertical alignment in the table

Trying to do something really simple here and I'm a bit stuck. Currently working on a forum project, and surprisingly the backend is error-free (thanks to some questionable magic tricks), However, my current task is to display all subcategories using ...

arbitrary arrangement of elements within container element

I need assistance with positioning random elements inside a DIV. These elements have varying LEFT and TOP positions within the parent element <div class="main"></div>. How can I mathematically calculate and set these positions using JavaScript/ ...

What is the best way to conceal a sticky footer using another element?

I have a footer that remains fixed at the bottom of both long and short pages. Below is the CSS code for this footer: .footer{ position: absolute; bottom: 0; width: 100%; height: 100px; background-color: white; } My goal is to achieve a 'r ...

Tips for preventing the larger background from displaying a scroll on a web page

Specifically tailored for this specific page: I am looking to eliminate the scrollbar at the bottom of the browser, similar to how it appears on this page: Thank you ...