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.