You want to use @font-face
, then you realize it’s got some downsides. First of all, it’s another HTTP request, and we know that the golden rule of web performance is to keep HTTP requests to a minimum. Secondly fonts aren’t even small files, they can be 50k+ in size. Lastly the lag of fonts loading last means you page seems to morph into it’s final form.
Here’s a cool little optimization. By using a data: URL you can use the font inline by encoding in base64. For example:
You can see this in action here. This seems to work fine in Firefox 3.5, and Safari 4 (presumably any modern WebKit based browser). Other browsers will simply act as if they don’t support @font-face
.
In practice I’d recommend putting it in a separate stylesheet rather than inline CSS so that your pages are smaller and CSS can be cached for subsequent page views.
Data URL’s are part of Acid2, which most modern browsers either pass or plan to pass. If you use an Open Type font you’d get pretty decent compatibility (IE only supports Open Type). Using True Type you’d still get pretty good compatibility sans IE. Check the @font-face page on MDC for more details. Unlike images, browsers that support @font-face
are likely to support data: URL’s as well, making this a pretty good solution.
Special thanks to Open Font Library for having some nice free fonts with awesome licensing. This post was partially in response to a comment left the other day on my @font-face hacks blog post.