<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Trevor Burnham &#187; Typekit</title>
	<atom:link href="http://trevorburnham.com/tag/typekit/feed/" rel="self" type="application/rss+xml" />
	<link>http://trevorburnham.com</link>
	<description>Sure, it works in practice...</description>
	<lastBuildDate>Thu, 24 Jun 2010 12:36:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flicker-free Typekit</title>
		<link>http://trevorburnham.com/2010/01/28/flicker-free-typekit/</link>
		<comments>http://trevorburnham.com/2010/01/28/flicker-free-typekit/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 01:26:22 +0000</pubDate>
		<dc:creator>Trevor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Typekit]]></category>

		<guid isPermaLink="false">http://trevorburnham.com/?p=254</guid>
		<description><![CDATA[I’m a fan of Typekit. Being able to go beyond the old Arial-​​Verdana-​​Times-​​Georgia paradigm, on any modern browser, without Flash (unlike sIFR), and with selec­table text (unlike Cufón), is a dream come true. One problem, though: It takes a few mil­lisec­onds to load up and render those fonts. That’s not so bad in itself; what’s bad is that the browser renders every­thing in non-​​Typekit fonts first, creating an annoying flicker every time the page loads as the text gets replaced by fancier fonts.]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update:</strong> On May 14th, 2010, Typekit finally announced an <a href="http://blog.typekit.com/2010/05/14/typekit-font-events/" class="liexternal">official solution</a> to the “flash of unstyled text” problem. So, the fix below should be considered obsolete.]</p>
<p>I’m a fan of <a href="http://typekit.com" class="liexternal">Typekit</a>. Being able to go beyond the old Arial-Verdana-Times-Georgia paradigm, on any modern browser, without Flash (unlike <a href="http://wiki.novemberborn.net/sifr/" title="Scalable Inman Flash Replacement" class="liexternal">sIFR</a>), and with selectable text (unlike <a href="http://cufon.shoqolate.com/" title="Pure JavaScript text replacement" class="liexternal">Cufón</a>), is a dream come true.</p>
<p>One problem, though: It takes a few milliseconds to load up and render those fonts. That’s not so bad in itself; what’s bad is that the browser renders everything in non-Typekit fonts first, creating an annoying flicker every time the page loads as the text gets replaced by fancier fonts.</p>
<p>Fortunately, there’s a fairly easy solution (though not an officially supported one—see below). Just add this to your site body:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;body id=&quot;domain-com&quot;&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;http://use.typekit.com/KIT_ID.js&quot;&gt;&lt;/script&gt;
  <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domain-com'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">opacity</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;document.getElementById('domain-com').style.opacity = 1&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Typekit.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'KIT_ID'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
      afterLoad<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;document.getElementById('domain-com').style.opacity = 1&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  &lt;!-- content goes here --&gt; 
&lt;/body&gt;</pre></td></tr></table></div>

<p>Then substitute your actual domain for <code>domain-com</code>, and (<strong>important!</strong>) your site’s unique Typekit ID for <code>KIT_ID</code>. You can get this ID by logging in to Typekit, launching the Kit Editor, and clicking the “Embed Code” link; it’s an 8-letter alphanumeric combination.</p>
<p>Here’s a breakdown:</p>
<ol>
<li>The <code>&lt;body&gt;</code> ID on line 1 isn’t just a good selector; <a href="http://css-tricks.com/id-your-body-for-greater-css-control-and-specificity/" title="CSS-Tricks: ID your body for greater CSS control and specificity" class="liexternal">it’s good form</a>. The most common convention is to use your domain (with a dash instead of a dot), which makes things easier for the <a href="http://userscripts.org/" title="User scripts" class="liexternal">Greasemonkey types</a>.</li>
<li>The script include on line 2 brings in the Typekit description of your site’s kit. You can move this line up to your <code>&lt;head&gt;</code> section if you want.</li>
<li>Line 4 makes your entire site disappear. Because this is at the top of your body, nothing is going to get rendered. It’s important that this line be here, rather than in another file or even at the foot of your body.</li>
<li>The call to <code>Typekit.load</code> does the actual loading of the fonts, and the <code>afterLoad</code> callback will be executed right after that happens. That’s when we want to make the body opaque again, right? Well, not quite. It seems that there’s a small delay between the callback and text refresh. Fortunately, using <code>setTimeout</code> to add a tiny delay (1ms) seems to eliminate this, finally ridding us of the dreaded flicker.
</li>
</ol>
<p><strong>Caveat:</strong> The <code>afterLoad</code> event is currently considered <a href="http://gist.github.com/192350" title="Code released by Typekit but not yet ready for live sites" class="liexternal">experimental</a>. An official solution for avoiding flicker is likely to be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://trevorburnham.com/2010/01/28/flicker-free-typekit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
