Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I only use Latin subset with Google Fonts WOFF2 files?

Tags:

I wanted to add a font with Google Fonts, and I have noticed an odd behavior.

I want to add a font with only the latin subset, I do not want latin-ext, cyrillic or cyrillic-ext subset, in order to lighten the code. I understand that's the default behavior, so I've done like this:

<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Philosopher"> 

In Firefox (and the other browsers that do not support WOFF2), I get a correct output:

@font-face {     font-family: 'Philosopher';     font-style: normal;     font-weight: 400;     src: local('Philosopher'), url(http://fonts.gstatic.com/s/philosopher/v7/OttjxgcoEsufOGSINYBGLbrIa-7acMAeDBVuclsi6Gc.woff) format('woff'); } 

But in Chrome, I get this:

/* cyrillic */ @font-face {     font-family: 'Philosopher';     font-style: normal;     font-weight: 400;     src: local('Philosopher'), url(http://fonts.gstatic.com/s/philosopher/v7/OttjxgcoEsufOGSINYBGLV4sYYdJg5dU2qzJEVSuta0.woff2) format('woff2');     unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; } /* latin */ @font-face {     font-family: 'Philosopher';     font-style: normal;     font-weight: 400;     src: local('Philosopher'), url(http://fonts.gstatic.com/s/philosopher/v7/OttjxgcoEsufOGSINYBGLZQV2lvL5Ba9FjAYK6Lx0Qk.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; } 

I thought, maybe the latin subset is not a default behavior anymore, so I added to my <link> the subset GET parameter:

<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Philosopher&subset=latin"> 

But it didn't change the output. When I go with a &subset=cyrillic, it changes in Firefox, but the Chrome output is the same.

Is there a way to output only the latin subset?

Or is just that the WOFF2 and unicode-range won't be downloaded if there is no need on the page? And in this last case, the gain from stripping the cyrillic call is just 8 lines of code ine the css file, that to say ~300 bytes, and it just doesn't worth anything?

like image 700
webdif Avatar asked Nov 03 '14 18:11

webdif


People also ask

What are Google Fonts subsets?

Subsetting is the practice of creating a “subset” of a font—a file that contains a custom (and usually limited) collection of glyphs. There are numerous scenarios where subsetting may be desirable: When a font delivery service wishes to optimize the file size of a web font.

How do I download WOFF files from Google Fonts?

While there is not a mainstream CDN for all the formats, you can use http://google-webfonts-helper.herokuapp.com to download the font files and host them yourselves.

Are Google fonts OK for commercial use?

Yes, you can use them commercially, and even include them within a product that is sold commercially. Usage and redistribution conditions are specified in the license. The most common license is the SIL Open Font License.


1 Answers

The trick lies with this optimization:

unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; 

With this, the browser knows whether it needs to download the font, depending on the characters it just loaded in the html. Chrome is currently the only one with full support for this.

MDN lists Firefox 36+ as completely ignoring this spec, therefore Google Fonts has to serve it a minimal font-face specification. The same happens with Safari.

Anyway, that was an interesting 30 minute journey on the internet which I hope helps any further internet travellers. This should lend weight towards why you could use Google Fonts as a CDN for hosting fonts for optimal performance as opposed to serving it yourself.

like image 89
Daryl Teo Avatar answered Sep 21 '22 18:09

Daryl Teo