A proposal for CSS to let web developers override CSS's lazy loading behavior.
#Background# By design, in CSS, assets like fonts are lazy-loaded.
This is a sane default behavior, as it allows web developers to re-use the same CSS file containing all the required definitions accross all pages in a given website without having to worry about superfluous downloads of assets. It also enables the unicode-range behavior in @font-face.
Unfortunately, in the case of fonts, this also contributes to the "blank text" problem: the page appears rendered but the text content is invisible for a while. This is because the font is only downloaded when it has been determined that it’s absolutely needed.
A good web developer should have a good idea of which assets are critical.
For fonts, while the Font Loading API offers a solution to these problems, it requires JavaScript and a non trivial amount of effort from web developers. Also, if you use a third party library for your asset loading needs, it introduces an extra RTT.
#Strawman# Allow web developers to give hints to the user agent about which assets matter.
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans'), local('OpenSans'),
url(http://example.com/opensans/normal400.woff2) format('woff2'),
url(http://example.com/opensans/normal400.eot) format('eot');
}
.myawesomebg {
background-image: url('awesome.png');
}
.maintext {
font-size: 2.5em;
font-family: 'Open Sans';
font-weight: 400;
}
@will-use {
.maintext;
.myawesomebg;
}
In which case the user agent can infer that actively downloading Open Sans 400 as well as awesome.png should pay off.
#Contributors# With advices/contributions from: Tab Atkins, Ilya Grigorik, David Kuettel.