Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't Google Fonts caching on Firefox?

I'm trying to use the embedded Google fonts on my website and I have included the link to download the font from Google fonts API every time someone visits the website, but I am having a problem with Firefox because it seems like its trying to download the font every time a refresh or click a new link.

On all the other browsers it only download once and cache the font through out the site like any other cached things.

The link to Google font API stylesheets is as follows:

<link href='http://fonts.googleapis.com/css?family=Droid+Sans&subset=latin' rel='stylesheet' type='text/css'>
like image 843
Dee-M Avatar asked Nov 24 '10 09:11

Dee-M


1 Answers

I noticed the same behaviour; loading the fonts with JavaScript seems to solve the problem. Just replace 'Ubuntu' with 'Droid' in your case and insert the following block of code after your <head> tag:

<script type="text/javascript">
  WebFontConfig = {
    google: { families: [ 'Ubuntu' ] }
  };
  (function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
        '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
  })();
</script>

More info can be found here on Google Developers' Font site.

like image 177
Geoff Avatar answered Sep 25 '22 16:09

Geoff