Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL redirects direct to Google font files #15

Open
zachleat opened this issue Jun 21, 2017 · 4 comments
Open

URL redirects direct to Google font files #15

zachleat opened this issue Jun 21, 2017 · 4 comments

Comments

@zachleat
Copy link
Owner

zachleat commented Jun 21, 2017

Loading a Google Fonts requires you to either use a JavaScript loader or load a blocking stylesheet (sample for Open Sans). For easier customization, provide a service that redirects directly to the Google font files, to use with your own CSS and @​font-face rules.

For example, when using Open Sans you’d normally have to use <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans">.

Using this service, you can inline your own stylesheet and reference the urls directly:

@font-face {
  src: url(https://googlefontredirect.com/opensans/latin/400/normal.woff2) format(woff2);
}

Url mapping: FAMILY_NAME/CHARACTER_SET/FONT_WEIGHT/FONT_STYLE.FONT_FORMAT

Redirect to https://fonts.gstatic.com/s/opensans/v14/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2

This wouldn’t eliminate the two hop limitation, but it would allow you to use it in preload or an inlined stylesheet for better performance.

When the cached urls expire, the redirects would update automatically.

@zachleat
Copy link
Owner Author

the font URLs are cached for a year, while the css URLs are cached for a day

https://twitter.com/googlefonts/status/862870935975714816

@felipesanches
Copy link

I'm not sure if the Google Fonts API will ever serve variable fonts, but it would be good to take that into consideration. OpenType Variable Fonts is a relatively new topic to me so I'm also not sure there would be any kind of optimization made possible by API queries to the server. But the URL may not involve a specific weight value, for instance, as the font file would basically (parametrically) contain the whole design-space of a full family in that hypothetical scenario.

I'm just thinking aloud here. I don't really have any specific suggestions at this moment other than that you should think a bit about these possibilities as well.

@thedavidthomas
Copy link

Have you seen Google Fonts Complete and PostCSS-Font-Magician by @jonathantneal?

@zachleat
Copy link
Owner Author

Very cool @thedavidthomas, love the postcss plugin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants