Fighting the @font-face FOUT
FOUT is what I'm calling the flash of unstyled text that you get while using @font-face in Firefox and Opera.
In June, Remy Sharp documented the how a browser progressively renders a page using @font-face. Things work differently between browsers natch:
Here's how in Firefox; basically the text is in a default webfont until the custom font is ready:

Webkit takes a very different approach, and very intentionally. They believe it's better to keep the text invisible until the font is ready. This way, there is no moment where the text flashes into its newly upgraded self. (This moment should be familiar to you if you've used sIFR)

I really don't like the text upgrade FOUT, so I personally prefer webkit's technique. But either way, we want the font loaded ASAP, so let's speed it up!
Best practices for serving fonts:
- Minimize the overall kilobyte size of your font file. You can reduce the size of your font file by subsetting it (more on this later).
- Heavy caching via a far-future expires header.
- Gzip?
Well, no; you can't gzip a font file, though you can gzip a css file that holds the data-uri representation, but you don't get much gain there. It'd primarily be an obfuscation technique.Stoyan Stefanov has done some excellent research into @font-face and gzip. Summary: It's possible! 40-45% savings. Do It!
When exactly do browsers download the font file?
Garrick at Kernest tipped me off to IE's interesting behavior here.
After some research we can see when the asset download is initiated:
- IE will download the .eot file immediately when it encounters the @font-face declaration.
- No browsers download the font file when they find a css rule that references the @font-face font.
- Gecko, Webkit, and Opera all wait until they encounter HTML that matches a CSS rule with a fontstack including the @font-face font.
I've put up a test page where you can experiment and watch your dev tools to see when the file is grabbed.
In what cases will you get a FOUT
- Will: Downloading and displaying a remote ttf/otf/woff
- Will: Displaying a cached ttf/otf/woff
- Will: Downloading and displaying a data-uri ttf/otf/woff
- Will: Displaying a cached data-uri ttf/otf/woff
- Will not: Displaying a font that is already installed and named in your traditional font stack
- Will not: Displaying a font that is installed and named using the local() location
Defeat the Firefox FOUT entirely #1: hide the page
The one serious caveat to this technique is: The page will not be visible until all content, iframes, remote scripts, fonts, and images are downloaded. for a maximum of three seconds (I added a three second bailout condition, read below.)
This should run in the <head> somwhere:
(function(){ // if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT var d = document, e = d.documentElement, s = d.createElement('style'); if (e.style.MozTransform === ''){ // gecko 1.9.1 inference s.textContent = 'body{visibility:hidden}'; var r = document.getElementsByTagName('script')[0]; r.parentNode.insertBefore(s, r); function f(){ s.parentNode && s.parentNode.removeChild(s); } addEventListener('load',f,false); setTimeout(f,3000); } })(); // a nice improvement to this script is to only hide the elements using webfonts // with visibility:hidden instead of the entire <body> // that's up to you to select them in that textContent line, though
2011.04.14 Added note about better technique through targeted selection
First, we are detecting if we're firefox 3.5+ by seeing if -moz-transform is supported, which was added at the same time. We use visibility:hidden instead of display:none, so that the font will actually be requested, and we remove that style once the page has finished loading. We're hinging on window load to be our re-entry point, because as Steve Souders pointed out, "font files block the window’s onload event from firing in IE and Firefox, but not Safari nor Chrome."
I've also added a 3 second bailout condition; this means if the page has not completely loaded in three seconds, we're going to show it anyway. It's possible the font won't be ready, but unlikely, I believe. This aims to solve the issue Remy found with the Standards.next site. I wouldn't recommend it, but you can disable this behavior by commenting out the setTimeout line.
Defeat the Firefox FOUT entirely #2: hide the text
I posted this over on html5rocks.com's tutorial: Quick Guide to Implement Webfonts via @font-face.
Accompanying the Google Font API is the WebFont Loader, a javascript library aiming to provide a number of event hooks giving you a lot of control over the loading. Let's take a look at how you can get other browsers to mimic WebKit's behavior of hiding the fallback text while the @font-face font loads.
<script src="//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
<script>
WebFont.load({
custom: {
families: ['Tagesschrift'],
urls : ['http://paulirish.com/tagesschrift.css']
}
});
</script>/* we want Tagesschrift to apply to all h2's */ .wf-loading h2 { visibility: hidden; } .wf-active h2, .wf-inactive h2 { visibility: visible; font-family: 'Tagesschrift', 'Georgia', serif; }
If JavaScript is disabled, the text will remain visible the whole time, and if the font errors somehow, it'll fall back to a basic serif safely. Consider this a stop-gap measure for now; most webfont experts desire hiding the fallback text for 2-5 seconds, then revealing it. Low-bandwidth and mobile devices benefit greatly by this timeout. Understandably, Mozilla is looking to rectify this soon.
A more lightweight but less effective solution is the font-size-adjust property, currently only supported in Firefox. It gives you an opportunity to normalize x-height across a font-stack, reducing the amount of visible change in the FOUT. In fact, the Font Squirrel generator just added a feature where it tells you the x-height ratio of the fonts you upload, so you can accurately set the font-size-adjust value.
2009.11.08. Tweaked defeat FOUT code to have a 3 second bailout.
2009.12.14. Added the In what cases will you get a FOUT section.
2010.05.03 font-size-adjust (only supported in Firefox) normalizes x-height and may improve the FOUT.
2010.05.26: I removed a bunch of old stuff from this article; it was kinda outdated.
2010.08.24: I updated this article with how to prevent FOUT using the Google Font API's WebFont Loader.
- Firefox (as of FFb11 and FF4 Final) no longer has a FOUT! Wooohoo! http://bugzil.la/499292 Basically the text is invisible for 3 seconds, and then it brings back the fallback font. The webfont will probably load within those three seconds though… hopefully..
- IE9 supports WOFF and TTF and OTF (though it requires an embedding bit set thing– mostly moot if you use WOFF). HOWEVER!!! IE9 has a FOUT. :(
- Webkit has a patch waiting to land to show fallback text after 0.5 seconds. So same behavior as FF but 0.5s instead of 3s.
And… WebInk has written a small script called FOUT-B-GONE which takes these facts into account and helps you hide the FOUT from your users in FF3.5-3.6 and IE.

Pretty sweet!
I'm in Firefox 3.5 and I still see the text styled in the default font for a fraction of a section before the proper font is applied. I even tested your code on my own site and experienced the same problem.
@Jonathan Snook ,
Hah yeah, I should make that more clear. :) This will help, but it can't guarantee no more FOUT.
I'm working on duplicating the webkit technique inside gecko and presto, which will be a nice option for people that like that style. It'll basically use the @font-face feature detect and poll that until the font is ready, and then remove a
color:transparentsetting.what happens in webkit when it thinks it can get the font, but while getting it, something goes wrong? like the font is corrupted or w/e…
does it then show some sort of fallback or does the text never show up? :x
I call this FOUC as "Flash of Unfonted Content" :)
As for the Firefox, there's a ticket in Bugzilla already: https://bugzilla.mozilla.org/show_bug.cgi?id=499292
@seutje
I'm fairly sure you won't be stuck without text, so it'll fall back. Sadly they expose none of these events to the javascript, so we have no obvious way of knowing.
@bganicky
Very nice, thanks for the bug on this, Bohdan. I see Daggett claiming you can hook into a resize event, but I think he's imagining things. :)
I have to pitch in and say I absolutely, whole heartily disagree that FOUT is the wrong way about things. I appreciate you're not saying one is better than another, rather which you prefer.
Here's one page that always catches me out – and because my connection is slow at the moment (crappy ISP) – and more often that not I just give up on the page because it doesn't come down:
http://dl.getdropbox.com/u/43399/fout.png
@Remy Sharp
Thanks dude; appreciate hearing your feedback. I think the best possible solution would take into considering a user's bandwidth and estimate of the page load time. So slow/mobile would get FOUT, and fast would not.
If only such a trick was trivial do to.
Ahh, my experience is that, while initiating the download as early as possible will help, the FOUT (or FOFF – Flash Of Fallback Font – as I'm calling it ;) ) can only be totally eliminated by supressing the display of the page until you know that the @font-face font has totally propagated throughout the page.
I am not saying I have figured out the best way to do that, just that it's my belief, based on dealing with a similar problem, that it will prove to be the only totally reliable way.
Anyway: Excellent, thought-provoking work. Thanks to Garrick, too, for the insight.
We're learning!
Rich
Note that the setTimeout is likely to be needed in Gecko too in the future in the original ("remove the node" technique), and the size of the timeout needed is likely to depend on the load on the machine, etc.
If you want to ensure the insertion is "noticed", you probably need to flush layout after doing it.
Geez … all designers want is a wider selection of fonts … little did they realize they're heading for a minefield.
Very interesting post (and so is Steve's).
I giggled when I saw that 'fout' means 'mistake', in Dutch! Apropos :-p
For me: I'm happily ignoring all the suggestions under 'best-practices'. I don't like sub-setting – I *might* need that glyph, one day. The other two, while I understand the 'why', are overkill IMO.
I'm hoping that @font-face usage increases dramatically and that browsers-makers catch up, standardize and optimize – or fix – their handling of font embedding.
Cheers
@stk
I'm using FOFF (Flash Of Fallback Font) instead of FOUT because it amuses me that there is now a font format named WOFF. So we've got WOFF and FOFF.
(It makes me loff, what can I say?) FOUT will probably win out, though.
I'm just a curmudgeon at heart.
Cheers, rich
If you use document.write in the head of the document, you can still have your pages validate:
@Pete
IMHO, document.write() is more trouble than it's worth and certainly shouldn't be used to just for validation purposes. Regardless, what you say is true. :)
Thanks for taking the jQuery idea I had and running with it. I'm very new to this, but one thing that I like about the way I coded this was that I didn't have to hide all the elements on the page. Maybe you don't either, but the caveat that "The page will not be visible until all content, iframes, fonts, and images are downloaded" does seems like a drawback.
Although my jQuery example (here: http://boxcarpress.com/us/blog/2009/11/05/css-font-face-flickering-in-firefox-somewhat-solved/ ) made the whole disappear before fading in, in practice I'm only doing this to divs with the @font-face text. In other words, all the images are loading with content on the page, then the text fades in with the correct font in place. This gives the visitor time to look at content so that it doesn't seem like something is wrong. Also, on one page where I have a lot of images which will delay load time, I show a loading "spinner" gif to make it clear that more content is coming.
I hope this helps implementation for people who are scared of not showing anything until everything is loaded.
@Harold Kyle
Very nice. I like just targeting this technique to the elements containing @font-face text. I've updated my above code to reveal all content after three seconds, so that loooong loading pages don't make users wait for ages. Good for people on slow connections.
Of course if some future version of Firefox happens to change the behavior here you're still going to stick the user with that 3-second wall of nothing….
@Boris
Yeah…. Definitely is a huge risk. I'm not ready to recommend people do this, but it's there for the anal folk that detest the FOUT.
If there was an event to reliably detect when the font has loaded we would have less of a problem, of course.
@Boris In my jQuery js, just make the first line:
if(($.browser.mozilla) && ($.browser.version < '1.9.2')){…which would limit this to versions prior to FF 3.6. The point is you may limit the scope however you may like (although FF 3.6 beta and 3.7 pre-alpha still show FOUT). There is no perfect way to load the page, but this is a slight improvement over the text re-formating in front of every Firefox user (to me anyway).
doesn't work for me
You should check out TTFGen. http://www.ttfgen.com. It auto generates images from TTF files and CSS parameters. there's also a wordpress plugin…
Maybe I'm smoking crack, but there may be two (only) slightly more elegant ways of handling this:
Use font-size-adjust. It won't stop FOUT, but it will make it much less jarring to the user. I haven't tested FF's implementation, so I don't know how reliable it is. I also don't know how well it's supported in other browsers.
Use Javascript to detect the actual font-family applied to a chosen element. Honestly, I have no idea if this will work, but it's something I've been meaning to try.
Ideas:
Test the theory. See if Gecko accurately reports the *actual* font-family applied to the element, regardless of what it intends to do once the first-priority font is downloaded. I assume this is true since Firebug can accurately tell me the effective font-family for any element.
Proposed test:
Configure development web server to severely limit bandwidth for fonts.
Clear browser cache.
Run test page with similar JS w/ jQuery (I know you want a more general solution than jQuery, but I'm brainstorming here :)) and watch the fonts and console closely:
If Gecko works like we expect:
Use some JS w/ jQuery (similar to the above) like this:
Instead of adding an invalid element to the head or using JS to do the same thing, would the same technique work simply by applying a font-family rule to an existing element in the head?
hey Paul, good read. you really went in deep with this issue.
what about using the old staple of JavaScript preloading?? remember back in the day, preloading /choke/ rollover images?? since JS doesn't really know or care what it's downloading, theoretically can't you preload anything?? then it would be cached, I assume.
haven't tested it, but seems logical, no??
I realize that I am late to this party but this needs to be said, IMHO:
If you prefer the Safari way of displaying nothing until fonts are downloaded – fine! Thats your choice and your taste.
I think that getting to the content as quicky as posiible is better and wholeheartedly support Firefox's way of doing this. Although it can of course be improved. But until that happens, developers, please do not destroy my experience. Do not write scripts that will cause Firefox to mimick Safari. Respect your users!
I am appalled to see that people still thinks that everything should "look the same" in every browsers and consider doing UA sniffing to achieve desired effects. Are we back in 1998?
@Lars Gunther
amen!
i'm working on a site at dev.omsphoto.com, and put this code in the head.php file, and it shows up as text on the browser… is there something missing here? you can see it on the site now
@bob bingenheimer
The JavaScript should go inside <script> tags.
In text/html it's not possible to put "b" element in "head". Parser will close "head" and open "body" as soon as it sees "b", and then it may use error recovery to move some head-specific elements from body to head.
"No browsers download the font file when they find a css rule that references the @font-face font."
Something about that sounds wrong to me?
@porneL
Yeah. This behavior has seemed to work fine in all browsers. Similar thing with appending a b element to the documentElement or so.. But the technique seems to be okay here.
@Hawk
Nope. :)
so your technique is to hide everything for whole 2 seconds because some text in the page doesn't look pretty for 2 seconds?
way to prioritize!
@bit – It's a matter of preference. In some instances one might prefer that delay instead of all of the page fonts shifting to their proper @font-face shortly after load. With some designs, that delay+shift looks awful, with others it's barely noticeable.
Either way, it's really nice to have the option (thanks to Paul) to decide ourselves whether we'll have delay+shift or not. At the moment, it's the best solution.
@Jeff Couturier
Personally, I think this is an amazing hack. Thanks for sharing, I'm definitely going to use it on sites where @font-face is crucial to the design and the flashing is very distracting.
I just plugged in typekit's webfontloader to get tight JS control of font loading. Seems to work at this point, so I hope to be spared any further low-level load-time debugging!
http://github.com/typekit/webfontloader
Thanks, as usual great info.
Big issue that is not mentioned, WebFont Loader does NOT support: iPhone, iPad, iPod, or Android. So the page renders only with the fallback font even though this devices are capable of rendering @font-face fonts (svg)
http://github.com/typekit/webfontloader/issues/#issue/14
http://code.google.com/apis/webfonts/faq.html#Browsers_Supported
Hi, here comes another "experience report": Although not mentioned in this excellent tutorial any more, we've finally turned back to including a span tag in the head for simlicity reasons. You can do a
.... loadme ...without losing XHTML 1.0 transitional valdiation (the browser puts it back to the body anyways because it's just a pointless abuse of the DTD structure). We've placed the @font-face declaration and this tag as early as possible into the head, especially before loading bigger javascript chunks (which is a blocking operation, that helps in this case!) and the effect is "statistically good enough" to avoid the FOUT without having to blind out the whole text or site until "onLoad" – the latter makes the site "blink" between pages.
Using external scripts like the fontloader JS seemed to make things rather worse in comparison to in-the-head javascript and css because they infer an extra delay and give the Browser the chance to apply "advanced optimizations" in the load sequence.
All the best, Nikolaus
PS: don't forget to test very good on XP machines without font smoothing (which is default there). not sufficiently hinted webfonts look horrible there.
dammit, code broken. tryagain:
<head>
…
<object>
<span style="font-family: myWebFont; visibility: hidden; position: absolute">loadme</span>
<object>
….
</head>
@Nikolaus Have you tried applying the font to an existing valid HEAD element, such as TITLE, instead of adding a dummy SPAN element?
Let me try that again:
Looks like FF 3.6.11 has fixed the FOUT woot!
err well maybe is not completely fixed but it's almost un-noticeable.
For those of us who see text as something designed to be read, with aesthetic being secondary to that primary function, and who are using a browsers thankfully sane enough to display the text to the user as soon as possible, what measure would you suggest we take to prevent web developers fousting this technique upon their visitors?
I seem to have an issue where modernizr causes a second FOUT. You can see it (I hope) in Firefox here: http://firstlifeseries.com/media-coverage/ and the other pages on that site.
I've just now implemented the webfont.js method and it has removed the first FOUT, but there's still a second flash. If I remove the line that loads modernizr it goes away.
An easy solution might be to eliminate modernizr altogether (its only use on this site is for html5 tags). But it would be nice to find a genuine solution to the problem, so any thoughts or suggestions appreciated…
@Andrew Staffell
Upgrade to Modernizr 1.6. This issue has been fixed there.
Great article and great script. I recently combined this with Zoltan Hawryluk’s font smooting detection script and use it on all my websites. (combined-script download and information, Website only in German, readme.txt inside the zip file in English) Works great!
Since Opera also has the FOUT problem (at least as far as I tested this), I added a second condition to address Opera 10.5 an above, too:
Unfortunately I couldn’t find any suitable condition to address Opera 10.0.
Personally, I find this very helpful. I like the idea of loading the fonts before the page loads. It works really nicely and my clients love this solution. Cheers!
You don't have to call your CSS file in the api, you can set the following code as a default in your projects and then use google fonts freely.
JS
In your normal css file:
And then you just add your custom font to any of your tags:
In your normal css file:
The first code block got chopped =/
WebFont.load({
custom: {
families: ['Tangerine']
}
});
Has anybody here run into a FOUC that sticks?
In a new website I designed with two cool FontSquirrel fonts, Firefox 3.6 is intermittently ignoring my special font and resorting to the rollover for no apparent reason. Refreshing the page doesn't usually fix it, but navigating to a different page generally does. Totally bizarre! (and driving me crazy)
Fixed it. The problem seems to have to do with the old 'http://' vs 'http://www.' issue. A redirect pointing everything to the www version resolved the issue.
Thanks for the article,
Sorry if I will sound a bit dumb but just to summarize are you saying that writing a js script to hide all text for nn seconds is the best solution to date?
@Yuri
The best solution is probably the one here: http://www.html5rocks.com/tutorials/webfonts/quick/#toc-fout
and also here: http://24ways.org/2010/using-the-webfont-loader-to-make-browsers-behave-the-same
It requires a javascript library but you have full control and the page doesnt disappear. :)
Thanks a lot, I also found gzipping very useful as mentioned by Stoyan. Will do optimization tomorrow
@lucideer
I propose that browser vendors fix this shit so this shitty hacks aren't neccessary:
https://bugs.webkit.org/show_bug.cgi?id=25207
https://bugzilla.mozilla.org/show_bug.cgi?id=499292
I'm not sure I like the idea of implementing custom script to override default behavior either; especially a potential three second artificial lag. On the other hand, I agree it would be nice to avoid the sometimes jarring effect of "FOUT".
Not tested, but a thought: How about including a low-res (re-sampled vectors, no hinting, etc.) subset (say, alphanumeric and common punctuation) of your high fidelity font as a data-uri,and then relying on the prioritization of the font-family declaration to show the low-res version before the hi-fi version is loaded?
The biggest drawback I see of course is the ballooning of download size.
If it were possible to include an svg in the data uri, that might even help with mobile environments that don't support ttf or otf.
I leave it to someone with more time than I have to take this thought further if they deem it to have merit. :)
Cheers,
David Twist
you know what helped me with FOUT?
- putting font-face related css in separate stylesheet and including it before everything
if your using Typekit they added font events to control there FOUT problems.
https://typekit.assistly.com/customer/portal/articles/6852-controlling-the-flash-of-unstyled-text-or-fout-using-font-events
Hi
I had the same problem with Cufon – a flash of the unstyled text as the font loaded. I tried the visibility hidden trick before the font was replaced but IE did not support this (of course – the fonts remained invisible when visibility was reset to 'visible'). The solution was to use a negative text-indent rule on the elements to be cufon'd. Not sure if the same solution could be used on font-face.
Some more info here:
http://www.codem.com.au/streams/2010/web-development/cufon-and-the-flash-of-unstyled-text.html
Cheers!
Paul,
Man – I read this post before updating my site w/ html5boilerplate and font-face (Google Font API) and I felt that having the FF approach was best – to get the content out as fast as possible.
Now, after updating my site I find that font upgrade FOUT to be so ugly that I love the fact that WebKit keeps it invisible until all is downloaded. Going to have to apply some of the techniques here to mitigate. Glad you wrote about this.
Cheers
I have found a simpler way to fix the FOUT problem – not sure if anyone will approve but I think it's a little more straight forward.
Use css FF conditional statement to turn off font visibility
h2,h3,h4,h5,#mainnav a, x:-moz-any-link { visibility:hidden; }Then use jquery to turn on visibility when the page has loaded
jQuery(document).ready(function() { $('h2, h3, h4, h5, #mainnav a').css('visibility','visible'); });So that wouldn't work because document ready fires far too early.. most fonts wont be ready at that point.. in general, it's a race condition
but….
as of today there are two big changes which has totally shaken up the FOUT landscape.. namely..
Firefox won't have a FOUT as of ff4b12..
and IE9 now has a FOUT.
So yeah! wooo
Your script works great on FF3xx. Thanks.
Have you had an opportunity to test whether it works on IE9?
(FF4=no fout, IE9=fout …all some sort of practical joke gone wrong…)
Thanks again for the good work, makes @font-face viable for me.
@Paul I see you point but in testing it seem to work well so… go figure!
Ahhhh ff4 / ie9 bah!!!
Way to go to override a behavior the user should be in control of!
> First, we are detecting if we're firefox 3.5+ by seeing if -moz-transform is supported, which was added at the same time.
And way to go to do wrong feature detection!
hey there, browsing your solutions, and other webs around, including WebFont Loader from Google, here's mine.
In my case it was not easy to include all the css styles so I made this workaround to avoid making any style.
Hope you find it useful. Thanks for your help!
(last part, the html)
Loading…
(…)
Here's how I got my fonts to load high up on the page and fixed the FOUT problem enough for us to deal with it:
1. Load the @font-face first
2. Put a span right after this in the head section
3. Code the span so it is displayed off the screen eg.(top:-1000px)
CONTENTS OF @font-face.css:
/* hackish but loads the font first */ .load-font { top:-1000px; position:absolute; display:inline; visibility:hidden; font-family: 'VegurRegular'; } @font-face { font-family: 'VegurRegular'; src: url('vegur-r_0500-webfont.eot'); src: url('vegur-r_0500-webfont.eot?iefix') format('eot'), url('vegur-r_0500-webfont.woff') format('woff'), url('vegur-r_0500-webfont.ttf') format('truetype'), url('vegur-r_0500-webfont.svg#webfontLyK1FZ0K') format('svg'); font-weight: normal; font-style: normal; }Missing code from last post:
Hey Paul,
We have written a FOUT script that expands on your initial work and would like to share it with the community. FOUT-B-Gone – as we call it – will control FOUT for @font-face calls. Right now we cover IE7-9 and FF3.5/3.6 but we should have an Opera modification to the script soon. And as we all know there is no reason to cover FF4 as it has FOUT control built in it.
http://www.extensis.com/en/WebINK/fout-b-gone/
This will work for local @font-face calls inside your own CSS files. We don't recommend this for use with services that host your CSS on their domain as you will see script errors in Firefox do to cross domain security issues. We are looking into a version that is not as robust but handles this issue, basically removing the CSS inspection that we do to figure out what @font-face calls are coming down on the page.
If anyone has comments or issues please let us know at webink@extensis.com
Brad
@Adam FLorin
I use WebFontLoader and do the essentially the following:
.wf { }
.webfont-a { font-family: "webfonta", arial, verdana, sans-serif; }
.webfont-b { font-family: "webfontb", georgia, times, serif; }
.wf-loading .wf { visibility: hidden; }
.wf-active .wf { visibility: visible; }
Hello!
Hey!
Found that eliminates any issues with FOUT. Tested with CharlesProxy on slower connections and there is a noticable delay in the appearance of content but its no different than waiting for images, side-bars, etc to come down, etc.
@Paul Michael Smith
Doh, Hello! & Hey! should have been
[code]
Hello!
Hey!
[/code]
Thanks for the update!
Regarding the remark that IE9 "requires an embedding bit set thing", in the 2011.04.14 update, this appears to be a non-issue. IE9 requires this only from raw TTF/OTF fonts but not WOFF or EOT fonts. And since IE9 accepts the latter formats too, it can be served webfonts without any format fulfilling this requirement. I tried a summary and, following your link, realize now that you effectively said so when you suggested to "solve this by [...] serving a WOFF". With the exception of Safari, WOFF is now supported by all major browsers.
Great write-up!
I think I agree with Remy Sharp though. I think that a short flash would bother me less on a fast connection, than a never-ending wait would on a slow connection…
Also, in these days of WPO (and Google stating 100ms as a goal), delaying all text (or even worse, the whole page) for up to 3 seconds seems like a step in the wrong direction.
I really can't understand what's all about that FOUT. I don't bother if the @font-face fonts display now or then or 2 seconds sooner or later as long as the text IS there. I think it's pretty trivial if there is another font for a short period of time or if it looks ugly. I think this FOUT thing is a little bit blown out of proportion …
WebInk's solution doesn't work with :first-letter
.dropcap:first-letter { font-style: none; float: left; font-family: eurofurence light, arial; font-size: 250%; line-height: 0.5em; margin: 18px 13px 0 0; }I see some other problem with Firefox4 – it is NOT caching the fonts in TTF or WOFF format. I tested this on Open Suse 11.4 and Windows with FF 4.01.
The webserver (NGINX) is sending the correct MIME types and also an expiry headers:
Server nginx/0.7.65
Date Mon, 02 May 2011 10:35:33 GMT
Content-Type application/x-font-ttf
Content-Length 30844
Last-Modified Tue, 05 Apr 2011 15:09:54 GMT
Connection keep-alive
Expires Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control max-age=315360000
Accept-Ranges bytes
All other browsers (including legacy FF3.6) are caching the files. FF4 doesn't cache them => there is a 1-2 second delay in displaying texts with the custom font on EACH page.
Even IE9 is getting this right!
I am disappointed to see that after the discussions about fonts, FF4 is fucking up this part.
I also added expires to .htaccess. With google font api described in this doc, everything seems to be working nicely. I think the .wf-loading isn't even triggered (it's so great!).
AddType application/vnd.bw-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-woff .woff
ExpiresActive On
ExpiresByType application/vnd.bw-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-woff "access plus 1 year"
I'm using fout-b-gone but it makes appear my text 7 secondes after loading, while the font is ready after some miliseconds.
Does someone know why?
Thank you Paul, and everyone who's added to this article. Simply fantastic.
Hey man
Your website is killing my browser in linux
You spend so much time with this stupid draw thing in the background that it uses 2+ gigs of ram (in firefox)
Weak programming man
@Shitty site
FYI, Win7 + IE9 on this site is using about 10 meg of memory.
Maybe you should upgrade your OS and browser ;)
It’s really a great and helpful piece of info. I’m glad that you shared this useful information with us. Please keep us informed like this. Thank you for sharing.
Anyone else seeing an error in IE8 with FOUT-B-Gone? I'm getting an "HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
?
Strange, I moved it just under the body tag (and out of the header) and the pages now load in IE8 with no parsing errors.
Paul already mentioned it on the last update, but let's recap a little: it seems "some delayed FOUT" is going to be the norm across browsers.
"Normal" (i.e. just using @font-face) font loading is widely supported, and it seems major browsers are aiming to this sequence:
(1) render blank for some seconds (0.5s < t < 3s)
(2) render text with fallback fonts until download finishes
(3) render text using webfonts
IMO, the Webfont Loader may not provide any benefit over this sequence, and will just add unnecessary overhead (extra JS download/execution and extra CSS maintenance).
I've briefly tested (but will appreciate someone else testing and confirming) that both Firefox 5/7 and Chromium 13/14 already present the behavior of falling back to locally available (system) fonts.
As a proof of this, Firefox includes the setting "gfx.downloadable_fonts.fallback_delay" (set to 3000ms by default). In the case of Chromium, I couldn't find any clue that this mechanism was already implemented, but I've done some tests by delaying the loading of the webfont, and it seemed to follow the above sequence.
So, bottom line: in the current state of affairs, I see no reason to continue using the Webfont Loader solution, even if IE9 is reported to just do steps 2 and 3 of the above sequence (i.e. no blank rendering at the very beginning of page load).
I like the acronym FOUT (flash of unstyled font). I think you have taken it from FOUC which stands for Flash Of Unstyled Content. FOUC occurs when you add your CSS at the bottom of your page.
@Lars Gunther I'm late to this too, but agree here.
Whether you are a web developer or a designer, you are [supposed to be] taught that the primary goal of your job is communication. Hiding information is not communicating. It's self-serving and we aren't supposed to be in the business of making ourselves happy, we're supposed to be doing our jobs for the end-user.
The problem that is being dealt with is the delay caused by load time of a file that takes time to load. And this solution is add code to the HTML document – which increases file size. That's working across purposes. Although in this age, for most users the added code is still virtually a non-factor, it still takes away load time for the font. Additionally, anyone so consumed with site appearance to need this method probably loads the site with graphics, so the site itself is already slow-loading. Adding more code doesn't help.
I know this comment is well after the article went up, but I just read it today – and probably others are just seeing it for the first time, as well.
While I don't agree with the technique described in the javascript unless it only affects the web text, I don't think that we're talking only about self-serving principles when we're dealing with manipulating the default behaviors of font-face here. Personally, the reason font-face seems so essential to me is readability. Having font variety can add to readability and emphasis(can). And if the (subtle) purpose of using font-face is indeed readable emphasis, then having a jarring FOUT will far overshadow that benefit.
Anyway, the solution I intend to follow, in the vein of the approach above, is adding an animated effect in time with loading problems. Essentially instead of providing nothing via js, performing a slight fadein so that users know to expect something. I'll see how that works out.