tags:

views:

50

answers:

2

So I have this stack:

 @font-face {
    font-family: 'MyCustomFont';
    src: url('MyCustomFont.ttf') format('truetype');
 }

 body { font-family: Helvetica, MyCustomFont, Arial, sans-serif; }

Is MyCustomFont.tff loaded by browser even if Helvetica is present in the machine (ie: Mac Users)?

+1  A: 

You need to use the local directive to test for the locally installed version of the font. If it is not found, the next font in the list will be tested for, and loaded if available. For example:

@font-face {
    font-family: MyHelvetica;
    src: local("Helvetica Neue Bold"),
    local("HelveticaNeue-Bold"),
    url(MgOpenModernaBold.ttf);
    font-weight: bold;
}

The above example was taken from here:
https://developer.mozilla.org/en/css/@font-face

There's some more information here:
http://www.broken-links.com/2009/06/30/checking-for-installed-fonts-with-font-face-and-local/

Once a font has been downloaded, it will be cached by the browser. Once in the cache, it will not be necessary for the browser to download the font again, thereby speeding things up. See here for more information:
http://code.google.com/apis/webfonts/faq.html#Performance

Mike
I know, the font is cached by the browser but, in case of MgOpen Moderna, it still weights ~60kb and it affects performance and bandwith. You're right, using the local directive is the standard, however it is sadly unsupported by IE and in Linux environments there are already a lot of Helvetica alternatives (too many to declare all with local). There are also other downsides using the local directive: see http://typophile.com/node/63992I was just searching for a smart way to optimize things :)
achairapart
@achairapart: I agree. The use of web fonts is a step in the right direction (moving away from image replacements), but it is by no means perfect. I have many variants of Helvetica installed on my computer, but there's no guarantee that I'll have the one you're testing for. For now at least, I think you have to either take the performance hit of downloading web fonts, settle for the few reasonably standard 'web safe' fonts, or just cross your fingers and hope for the best ;-)
Mike
A: 

You could try checking it out with httpfox (an extension for firefox) on a computer which has the helvetica font installed. But remember that the behavior is probably browser dependent.

Knu