News for hackers. Stuff that matters.
Re:Google Webfonts, the Spy Inside? by kbar13 on Friday February 20, 2015 @06:38PM (#9083830)
using font files from a popular public cdn like google fonts is a good idea as they are generally highly available and are generally already cached on the user's machine from use on other sites.
Re:Google Webfonts, the Spy Inside? by Throwaway90283 on Friday February 20, 2015 @07:51PM (#9084124)
Keep in mind the Google CDN is blocked in countries such as China, so your web fonts are not going to render for those visitors, and if you rely on jQuery from the Google CDN, those visitors will experience a broken site. If you have a global reach, this is one reason to self host.
Re:Google Webfonts, the Spy Inside? by acdha on Friday February 20, 2015 @08:59PM (#9084344)
Interestingly, that's true for scripts but it's not for webfonts because @font-face allows multiple sources, including local system fonts, and the browser will keep trying until it finds one which works.

Here's a test page: http://chris.improbable.org/experiments/browser/webfonts/web...

You can see that it first gets a 404 before continuing on to a URL which works:

http://www.webpagetest.org/result/150221_J4_43K/1/details/

Re:Google Webfonts, the Spy Inside? by oxplot on Saturday February 21, 2015 @01:38AM (#9084918)
Steve Souders from Google goes through dealing with this [1] and I was surprised to see how Twitter approached this (basically encouraging putting sync javascript link at the top of the page)

[1]: https://www.youtube.com/watch?v=aHDNmTpqi7w

Re:Google Webfonts, the Spy Inside? by cozuya on Friday February 20, 2015 @08:35PM (#9084286)
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script> <script> window.jQuery || document.write('<script src="/js/jquery-1.9.1.min.js"><\/script>'); </script>

This has to be pretty standard in 2015 right?

Re:Google Webfonts, the Spy Inside? by detaro on Friday February 20, 2015 @08:49PM (#9084317)
This still has to time out on the first request to trigger, right?
Re:Google Webfonts, the Spy Inside? by acdha on Friday February 20, 2015 @09:00PM (#9084349)
Yes – you could do something creative with async scripts but then you're transferring too much data for everyone to benefit only the subset of users who experience failures on the first script.
Re:Google Webfonts, the Spy Inside? by Nux on Friday February 20, 2015 @06:45PM (#9083864)
Kbar, why do you need "highly available" fonts when you can bundle them in your web site? If the web site is up, fonts will work, if not fonts won't be needed anyway.

Regarding caching, anyone knows how browsers cache content? I.e. if I host my own fonts and someone visits me, then visits another web site with same fonts.. are they retrieved from the cache or downloaded yet again? I'm guessing they are downloaded again which is unfortunate..

Re:Google Webfonts, the Spy Inside? by tschuy on Friday February 20, 2015 @07:20PM (#9084009)
> I'm guessing they are downloaded again which is unfortunate..

Which is exactly the reason to use a web font CDN like Google Fonts. I have Open Sans on my computer, and I'll redownload it again in a year when the cache expires. If each Wordpress blog started including their own copy, I'd have to redownload it each time.

Re:Google Webfonts, the Spy Inside? by lallysingh on Friday February 20, 2015 @07:25PM (#9084025)
AFAIK, the fonts are hosted as regular URLs with cache policies specified in HTTP headers. So, if you host your own fonts, and someone visits your site and someone else's site with the same fonts, they will download it twice (unless the other site's referring to your site in the URL). The browser doesn't know that they're the same font until after it downloads it (twice).
Re:Google Webfonts, the Spy Inside? by walterbell on Friday February 20, 2015 @07:49PM (#9084116)
Fonts are a small subset of a site that makes a conscious decision to use a third-party font. There are many other resources being downloaded, which may or may not be duplicated. If the sites are revisited, they will be cached.
Re:Google Webfonts, the Spy Inside? by pyre on Friday February 20, 2015 @07:09PM (#9083964)
Safari doesn't deal well with web-loaded fonts. I have seen Safari load corrupted webfonts from cache even when turning on "Don't Use Cache for Anything" in the Developer Tools menu. ... so there's always that.
Re:Google Webfonts, the Spy Inside? by GeneralMayhem on Friday February 20, 2015 @07:55PM (#9084140)
If they're not being loaded from the same url (e.g. from Google), then they're not the same fonts as far as the browser can tell.
Re:Google Webfonts, the Spy Inside? by a3_nm on Friday February 20, 2015 @07:21PM (#9084013)
It's a pity that there isn't currently a way to leverage cached resources with different URLs for the same content.

In fact this would not be hard: if you could indicate, with the resource URL, the hash of the resource content, the browser could just use the resource with that hash if it has it in cache (no matter from which URL), and otherwise retrieve it, check the hash, and add it to the cache.

Re:Google Webfonts, the Spy Inside? by kbar13 on Saturday February 21, 2015 @11:44AM (#9085969)
to be fair, what happens if there's a hash collision?
Re:Google Webfonts, the Spy Inside? by a3_nm on Sunday February 22, 2015 @11:20AM (#9089825)
Use a cryptographic hash function, and there will be no collisions. There are a lot of things that rely on the assumption that hash collisions do not happen.