Gravatar

Geoff Evason

Cross domain workaround for @font-face and Firefox

All major browsers (even ie4+) now support the @font-face css property, which is great news for designers.  Unfortunately there are still some kinks:

  • Different browsers support different formats.  You can specify multiple formats within a css file, and as long as you can provide .eot, .ttf, and .svg you’ll be okay.
  • Firefox (which supports @font-face from v3.5) does not allow cross-domain fonts by default.  This means the font must be served up from the same domain (and sub-domain) unless you can add an “Access-Control-Allow-Origin” header to the font.
  • At the time of writing, you cannot set the Access-Control-Allow-Origin” header on S3

I wanted to use @font-face served up from cloudfront – so here is what I did:

  1. Go to fontsquirrel.com and download the font-face kit you want to use.
  2. Go to the fontsquirrel font-face generator and upload the .ttf file from the kit you just downloaded.
  3. Select the ‘Expert’ option.
  4. For format select ‘TrueType’, ‘EOT’, and ‘SVG’.  (Woff is a compressed format only supported by firefox, but firefox also support .ttf, so woff is extraneous)
  5. Under the CSS options select ‘Base64′ Encoding.
  6. Download and use the files provided.

What does this do?  It actually embeds the TTF font within the CSS file, so it can be served up directly from S3/cloudfront and still work on Firefox.  This solution works, but is sub-optimal.  In particular, it bloats your css for other browsers (like mobile safari and IE) that can’t use the TTF format. :-(

  • Hermesite
    Working, it helped a lot. Thanks
  • Halter
    Hey there, I have been unable to download Base64 encoded files recently. When I press download, the wheel just spins but nothing happens. I figured that maybe font squirrel is having server issues, but could someone confirm this by trying a download? Regular non-Base64 files download fine for me.
  • Fluzz
    Hi,

    I am following your steps and am uploading a .TTF file, but when i download the kit there is not .TTF in the zip, just SVG and EOT!
    Have i missed something?
  • What font is it, and where did you get it from? Some fonts may not have TTF files I suppose.
  • Justin
    Thank you! :D
  • Samuel
    THANKS A LOT!!!! 2 days workin on it... finaly find your article.
    It works amazing now.

    Im was doing my new site (by me) and blog (by google), working in a layout that fits in the blogspot just like the site.

    I'm using Chrome for tests, and the font-face was working fine, until i tryied in FF... No fonts rendered... (i have to cross domain the css and the other stuff, all ok but the fonts)

    Now its working fine. I let the two kind of web-kit runing trough the css.

    estudiodrop.com.br / estudiodrop.blogspot.com
  • thanks it works
  • zen
    you've just saved my life today !!!! thanks
  • Was just wondering if I could use base64 (like I do on some images) to solve this problem, this article was the *perfect* guide on how to do it. Whew.
  • I upload the font, works fine, download the kit. I then unzip the kit and extract the ttf file and upload that.... then I get a "this font is blacklisted" notice from the generator. How is that possible when I was uploading that exact font?
  • I'm not sure why that would happen. Sounds strange... Perhaps you could ask font-squirrel... What font is it?
  • So I was using a font called Zegoe UI not provided by font squirrel, and I uploaded it via the optimal option. I get the TTF file and I try and upload that, it doesn't work. So then I try to just use the original Zegoe font and do the expert option and use base 64, but when I download the kit there isn't a ttf file. I tried this with one from font squirrel and its not working either... Am I doing something wrong?
  • Thank you so much for this! Fixes my Tumblr theme woes!
  • Stefan
    Helped me alot...
    Thanks
  • Ed Ascencio
    Amazing... thank you!
  • Thanks a lot for the tip. Big life saver.
  • Nilesh Patil
    Wow!
    Its working for me.
    Thanks for trick.
  • Excellent. Thanks for sharing - works a treat.

    µ
  • B E A U T I F U L !

    Thank you so much. And my thanks to
    Font Squirrel for adding it to their tool.

    -MG
  • Thanks for the trick!

    It's really stupid that FF enforces this restriction, when you can easily download that font and stick it on your server. In my case, all I wanted to host my css/js/font files on a separate subdomain for my tumblr!
  • Chris
    Thank you so much for this post, we've been beating our head against the wall on this problem today. FireFox FAIL!!! FAIL FAIL! It is ridiculous Mozilla doesn't support subdomains, most sites host static files under a subdomain.
blog comments powered by Disqus