Is it possible to reduce Google Web Fonts to one request if I'm using multiple fonts?
Asked Answered
R

4

7

I ran a speed test on my website and one of the suggestions was to reduce my external requests. I am using 3 Google Web Fonts, in effect 3 separate requests. Is it posible to combine these into 1 request?

Reld answered 19/12, 2011 at 20:12 Comment(0)
M
12

You can combine several fonts with just one call using the | character. Example:

<link href='//fonts.googleapis.com/css?family=Cantarell|Terminal+Dosis' rel='stylesheet' type='text/css'>
Montes answered 8/5, 2012 at 19:18 Comment(0)
I
1

Yes you can load multiple fonts in single request like

<link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css?family=Montserrat:400,700|Lato:300,400,700,900'>
Interscholastic answered 7/2, 2017 at 23:26 Comment(0)
U
0

Aren't Fonts (like image assets, JSON objects, or videos) separate resources that need individual requests?

Urinalysis answered 19/12, 2011 at 20:15 Comment(0)
C
0

You can avoid the three requests by embedding the fonts in data: URIs inside the CSS - at least in IE9+ and most modern browsers.

note: they also work in IE8, but are limited to 32KB

note2: obviously, you won't get the benefits of the Google CDN, since you'll have to serve the fonts inside your CSS...

Chantey answered 19/12, 2011 at 20:27 Comment(2)
I imagine the benefits of the Google CDN are > than loading them on my server + the 3 requests?Reld
Hard to say; Google's CDN will almost surely have higher bandwidth and lower latency. Moreover base64-encoded data take up more space. OTOH, it will require an additional DNS lookup and 3 requests instead of one (or zero, if you already have a CSS file). Benchmarking is the only way to know.Chantey

© 2022 - 2024 — McMap. All rights reserved.