I am using some Google Web Fonts. I hear that Google deal with all the issues between different browsers and serve different media depending on the browser in the request header.
My question is, at what point does it do this?
Reason being is that for the API you can simply include a CSS file which contains the @font-face
request. Can I simply include that CSS in my own CSS file, thereby saving a HTTP request, or does that CSS change depending on the browser that requests it?
I really hope that makes sense.
E.g., Google suggest you include the following in your CSS file:
@import url(http://fonts.googleapis.com/css?family=Exo);
the contents of which are:
@font-face {
font-family: 'Exo';
font-style: normal;
font-weight: 400;
src: local('Exo Regular'), local('Exo-Regular'), url('http://themes.googleusercontent.com/static/fonts/exo/v1/ZcGd2dvMSgl3mHN3lKAjNw.woff') format('woff');
}
The results show that Google Fonts load significantly faster from Google CDN. Even the locally hosted modules. tff font loads faster in the first case as compared to the second one. Adding many Google Fonts only exacerbates the performance further.
Serving Google Fonts Locally It not only improves user privacy but also helps to avoid potential complications from API downtime or performance bottlenecks. That being said, locally hosted fonts do mean more work for your web server. Thus, it's still important to utilize caching and other optimizations.
Should I use <link> or @import ? # Loading Google fonts in the HTML reduces the critical request depth and speeds up page load Always import your fonts from HTML, not CSS.
The CSS served up by Google Webfonts changes depending on the user agent in the HTTP request header, so you'd be better off using @import. The reason is the different implementations of web fonts in different browsers.
Not an answer to your exact question, but even if it were possible at the moment, I would never locally cache any CSS that Google serves "live" because:
even if it works now, it may break later if they change something
you do not add any reliability, because the font itself still has to be fetched from Google
you do not really improve performance much: if everything is configured correctly, the HTTP request will happen only once and be cached thereafter. Also, the user may have the font CSS cached from another site that uses Google Fonts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With