<?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>danbeam.org :: blog</title>
	<atom:link href="http://danbeam.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://danbeam.org/blog</link>
	<description></description>
	<lastBuildDate>Thu, 27 Oct 2011 02:28:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Page-speed for Firefox 7 + the future of extensions?</title>
		<link>http://danbeam.org/blog/2011/08/26/page-speed-for-firefox-7-the-future-of-extensions/</link>
		<comments>http://danbeam.org/blog/2011/08/26/page-speed-for-firefox-7-the-future-of-extensions/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 16:28:03 +0000</pubDate>
		<dc:creator>danbeam</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://danbeam.org/blog/?p=225</guid>
		<description><![CDATA[The problem I was trying to use Page Speed the other day &#8211; an awesome browser plugin (and/or apache module) made by Google to help make the web faster. However, I was tired of having 5 versions of Firefox to &#8230; <a href="http://danbeam.org/blog/2011/08/26/page-speed-for-firefox-7-the-future-of-extensions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>The problem</h2>
<p>I was trying to use <a href="http://code.google.com/speed/page-speed/" target="_blank">Page Speed</a> the other day &#8211; an awesome browser plugin (and/or apache module) made by Google to help <a href="http://code.google.com/speed/" target="_blank">make the web faster</a>.  However, I was tired of having <a href="http://twitpic.com/5mr48h" target="_blank">5 versions of Firefox</a> to chose from (or remember where I&#8217;ve installed various plugins), so I removed everything else and just kept &#8220;<a href="http://www.mozilla.org/en-US/firefox/channel/" target="_blank">Aurora</a>&#8220;.  Aurora is Mozilla&#8217;s equivalent of the dev channel build of Chrome (between nightly and beta).  Unfortunately, Page Speed only works on <a href="http://code.google.com/speed/page-speed/download.html#extension-rel-ff"  target="_blank">Firefox 4-6.*</a> (well, it doesn&#8217;t say the end range there, but <a href="http://groups.google.com/group/page-speed-discuss/browse_thread/thread/1683be623bd021f9" target="_blank">just trust me</a>).</p>
<p><a href="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.24.38-AM.png"><img src="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.24.38-AM.png" alt="" title="Before I hacked install.rdf" width="423" height="214" class="alignnone size-full wp-image-231" /></a></p>
<h2>The hack</h2>
<p>Figuring there really couldn&#8217;t have been that big of a difference between the two, like a good hacker I changed the <code>maxVersion</code> in the plugin&#8217;s metadata (in this case install.pdf in page-speed.xpi).  I&#8217;m not sure all plugins have these kinds of issues or are using the same method of versioning, but it seems relatively standard to Firefox plugins.  So, I wrote a script that&#8217;ll cURL the .xpi for me, do a tiny little bit of sed to change the <code>maxVersion</code> to <code>*</code> and re-zips it back into the current working directory (did you know .xpi is just a glorified .zip?).</p>
<p><a href="https://gist.github.com/1172951.js?file=gistfile1.sh">Here&#8217;s the script</a> if you&#8217;re lazy like me and don&#8217;t like waiting for plugin authors to simply bump versions.</p>
<p>And guess what? It worked like a charm!</p>
<p><a href="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.25.28-AM.png"><img src="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.25.28-AM.png" alt="" title="After I hacked install.rdf" width="429" height="249" class="alignnone size-full wp-image-232" /></a><br />
<a href="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.27.49-AM.png"><img src="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.27.49-AM.png" alt="" title="page-speed in FF7 (extensions menu)" width="834" height="247" class="alignnone size-full wp-image-233" /></a><br />
<a href="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.28.45-AM.png"><img src="http://danbeam.org/blog/wp-content/uploads/2011/08/Screen-shot-2011-08-26-at-1.28.45-AM.png" alt="" title="page-speed in FF7" width="1190" height="1028" class="alignnone size-full wp-image-234" /></a></p>
<blockquote><p><b>NOTE: I make no attempt to suggest this method of changing maxVersion isn&#8217;t totally stupid, dangerous, and just outright gross.  However, if you feel any of these things about this script/method &#8230; just don&#8217;t do it.</b></p></blockquote>
<h2>The hope</h2>
<p>I think as browsers continue to move toward versionless (or, er, version agnostic) software we&#8217;ll probably need to rethink the way we try to version packaged software.  Something like this obviously has maintenance costs associated with it for extension developers (and Mozilla doesn&#8217;t seem to care much, as they force you to recompile on every release even if youre source code hasn&#8217;t changed), so I doubt people will continue manual version bumping for long.  My guess is that they&#8217;ll either just bump to <code>*</code> or remove the <code>maxVersion</code> like I have, or will just simply stop maintaining plugins all together.</p>
<p>That said, using feature switches inside your plugin to check for a dependency or version of something sounds like a pretty good idea, if it&#8217;s technically feasible (not sure, never done large scale stuff with extensions).  That is what various places I&#8217;ve worked (Yahoo!, Google) do to hold back something that needs to be continuous integrated/deployed during development (see &#8220;about:flags&#8221; in Chrome to understand what I&#8217;m talking about, <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p>
<p>What do you think?</p>
<h2>Update:</h2>
<p><a href="http://www.linkedin.com/pub/nimrod-bar/0/764/76b">Nimrod Bar</a>, my former co-worker and maintainer of FoxyTunes (a Firefox add-on w/~150,000 users) also told me that you can achieve this same effect with the <a href="https://addons.mozilla.org/en-US/firefox/addon/nightly-tester-tools/" target="_blank">Nightly Tester Tools</a>.  I find it weird that installing an add-on would let you &#8230; install more add-ons (well, have enough access to do this), but it&#8217;s still cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://danbeam.org/blog/2011/08/26/page-speed-for-firefox-7-the-future-of-extensions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash 10 + Firefox 5 + Ubuntu = hell</title>
		<link>http://danbeam.org/blog/2011/06/29/flash-10-firefox-5-ubuntu-hell/</link>
		<comments>http://danbeam.org/blog/2011/06/29/flash-10-firefox-5-ubuntu-hell/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 05:24:35 +0000</pubDate>
		<dc:creator>danbeam</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://danbeam.org/blog/?p=206</guid>
		<description><![CDATA[For those fellow Linux nerds that are constantly annoyed by trying to have recent software that actually works, after an hour of messing with various stale (or not stale) guides, I have a one-liner for you that should install Flash &#8230; <a href="http://danbeam.org/blog/2011/06/29/flash-10-firefox-5-ubuntu-hell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For those fellow Linux nerds that are constantly annoyed by trying to have recent software that actually works, after an hour of messing with various stale (or not stale) guides, I have a one-liner for you that <b>should</b> install Flash 10 for you in Firefox 4 &#038; 5 in Ubuntu (I&#8217;m using 10.10, but this probably works on more than one version).</p>
<p>Here&#8217;s the command:</p>
<pre style="overflow-x:auto;"><code>sudo mkdir -p /usr/lib/flashplugin-installer &#038;&#038; \
cd /usr/lib/flashplugin-installer &#038;&#038; \
sudo curl -s http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz -O &#038;&#038; \
sudo tar xfz install_flash_player_10_linux.tar.gz &#038;&#038; \
sudo ln -nsf /usr/lib/flashplugin-installer/libflashplayer.so /usr/lib64/mozilla/plugins/libflashplayer.so &#038;&#038; \
sudo rm -rf install_flash_player_10_linux.tar.gz /usr/lib/flashplugin-installer/usr &#038;&#038; \
cd - >/dev/null &#038;&#038; \
echo "All done"</pre>
<p></code></p>
<p>Of course you should understand what this does before you run it (especially because it requires sudo) and it doesn't have to be in one line, but why not? <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://danbeam.org/blog/wp-content/uploads/2011/06/ff5_ubuntu10.10_flash10.2.png"><img src="http://danbeam.org/blog/wp-content/uploads/2011/06/ff5_ubuntu10.10_flash10.2-1024x827.png" alt="sweet success" title="ff5_ubuntu10.10_flash10.2" width="640" height="516" class="alignnone size-large wp-image-220" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://danbeam.org/blog/2011/06/29/flash-10-firefox-5-ubuntu-hell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Turns out there is block scope in JavaScript &#8230; kinda</title>
		<link>http://danbeam.org/blog/2011/05/23/turns-out-there-is-block-scope-in-javascript-kinda/</link>
		<comments>http://danbeam.org/blog/2011/05/23/turns-out-there-is-block-scope-in-javascript-kinda/#comments</comments>
		<pubDate>Mon, 23 May 2011 22:08:48 +0000</pubDate>
		<dc:creator>danbeam</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://danbeam.org/blog/?p=166</guid>
		<description><![CDATA[Block scope in JavaScript?! Yup, using an interesting hack that works in browsers that like the open web. You mean let? No, I&#8217;m not talking about JavaScript 1.7&#8242;s let statement (currently only implemented in Firefox 3.0+). I&#8217;m talking about using &#8230; <a href="http://danbeam.org/blog/2011/05/23/turns-out-there-is-block-scope-in-javascript-kinda/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Block scope in JavaScript?!</h3>
<p>Yup, using an interesting hack that works in browsers <a href="http://getfirefox.com">that</a> <a href="http://apple.com/safari">like</a> <a href="http://google.com/chrome">the</a> <a href="http://opera.com">open</a> <a href="http://beautyoftheweb.com">web</a>.</p>
<h3>You mean let?</h3>
<p>No, I&#8217;m not talking about JavaScript 1.7&#8242;s <code>let</code> statement (currently only implemented in Firefox 3.0+).  I&#8217;m talking about using <code>try {} catch (){}</code> in mischievous ways, <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h3>Where it started</h3>
<p>So, looking at an <a href="http://stackoverflow.com/questions/6100230/javascript-catch-parameter-already-defined">interesting StackOverflow question</a> I started hacking around with variables inside of the parens following a <code>catch</code> statement.  Here was my first attempt:</p>
<pre><code>try {
    JSON.parse('Throw some error');
} catch (e) {
    var x = "It doesn't introduce a new scope, but";
}
document.write(x); // It doesn't introduce a new scope, but
document.write("&lt;br&gt; e is " + typeof e); // e is undefined</code></pre>
<p>(<a href="http://jsfiddle.net/sZrGb/2/">the jsfiddle</a>)</p>
<h3>The Cool Hack</h3>
<p>OK, so something a little quirky is going on here.  <code>var</code> statements inside of a <code>try {} catch (){}</code> leak to the outside scope, but Exceptions passed to the <code>catch</code> statement don&#8217;t exist after that scope is left.  So after checking <code>this</code> and some other stuff as well (<a href="http://jsfiddle.net/sZrGb/3/">jsfiddle</a>) it looks like <code>try {} catch(){}</code> totally sets up a new block scope for the Exception you&#8217;re throwing to it.  </p>
<p>This lets us do interesting things like:</p>
<pre><code>var i;
for (i = 0; i < 3; ++i) {
    try { throw i; } catch (l) {
        // use l without fear of it changing
    }
}
</code></pre>
<p>(<a href="http://jsfiddle.net/CUbwA/17/">the cool hack</a>, <a href="http://jsfiddle.net/CUbwA/18/">the typical problem</a>)</p>
<p>in all browsers except ... you guessed it, IE.</p>
<h3>Everywhere but here (if "here" is IE6-8)</h3>
<p>So, the good news is that this <code>try { throw i; } catch (l) { }</code> hack does introduce a new block level variable without creating a new function (should be cheaper and not affect <code>var</code> statements inside the catch) in many platforms.  However, the bad news is that JScript < 9 implements <code>try {} catch(){}</code> in a different way from <i>everybody else</i> because they have a long history of doing things differently and why stop now?  (OK, OK - JScript 9+ acts the same as everybody else.)</p>
<p>Anyway, poking around with JScript 5.6-5.8 a little bit more I figured out they're simply creating a functionally scoped local rather than a block scope one.  Here's an example:</p>
<pre><code>(function () {
    var i = 5;
    try {
        throw i;
    }
    catch (c) {
        var l = 20;
        c = 50;
    }
    finally {
        var f = 100;
    }
    alert("l: " + typeof l + ", " + // "number"
          "c: " + typeof c + ", " + // "undefined" except
                                    // in IE6-8 it's "number"
          "f: " + typeof f);        // "number"
}());
alert("l: " + typeof l + ", " + // "undefined"
      "c: " + typeof c + ", " + // "undefined"
      "f: " + typeof f);        // "undefined"
</code></pre>
<p>(<a href="http://jsfiddle.net/CUbwA/16/">the fiddle</a>)</p>
<p>MSDN does mention that this Exception is a local <a href="http://msdn.microsoft.com/en-us/library/dww52sbt(v=vs.85).aspx">here</a>, but now <i>how</i> local.</p>
<h3>So, can I use this?</h3>
<p>This does mean that you can use this hack for sites or libraries not targeting IE, like things on Mobile (for now, unless you think Windows Phone 7 is gonna be big, lol) or solely Linux/UNIX/OSX or Firefox/Chrome/Safari/Opera user bases.  If you do want to support IE6-8 (<a href="http://gs.statcounter.com/#browser-ww-monthly-200807-201105">41.61%</a> of current browser market) don't use this hack as it will only work in IE9+ (if they stick to what they're doing right now).</p>
<h3>Conclusion</h3>
<p>I thought I had figured out how to emulate <code>let</code> in all browsers, but the story just turns out to be the typical one -- all browsers but IE.</p>
]]></content:encoded>
			<wfw:commentRss>http://danbeam.org/blog/2011/05/23/turns-out-there-is-block-scope-in-javascript-kinda/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>2295 script tags later</title>
		<link>http://danbeam.org/blog/2011/05/16/2295-script-tags-later/</link>
		<comments>http://danbeam.org/blog/2011/05/16/2295-script-tags-later/#comments</comments>
		<pubDate>Mon, 16 May 2011 17:58:01 +0000</pubDate>
		<dc:creator>danbeam</dc:creator>
				<category><![CDATA[Compatibility]]></category>
		<category><![CDATA[Cross-browser]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://danbeam.org/blog/?p=109</guid>
		<description><![CDATA[What I did So, building on my &#8220;Script: not a type-ical tag&#8221; article, I tested a few more ways to inject JavaScript into webpages. 1895 more, to be exact, (and I&#8217;m not done yet). How I did it Firstly, I &#8230; <a href="http://danbeam.org/blog/2011/05/16/2295-script-tags-later/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>What I did</h3>
<p>So, building on my &#8220;<a href="http://danbeam.org/blog/2011/05/06/script-not-a-type-ical-tag/">Script: not a type-ical tag</a>&#8221; article, I tested a few more ways to inject JavaScript into webpages.  1895 more, to be exact, <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (and I&#8217;m not done yet).</p>
<h3>How I did it</h3>
<p>Firstly, I changed the way I&#8217;m injecting scripts to use a PHP file like <a href="http://mathiasbynens.be/">Mathias Bynens</a> is in his <a href="http://mathiasbynens.be/demo/javascript-mime-type">tests</a> (i.e. page.php?type=blah/blah&#038;do=something).  Here&#8217;s the end result for that PHP file:</p>
<pre><code>&lt;?php

$ct = preg_replace('/[^a-z\/\-]/', '', $_GET['ct']);
header('Content-Type: ' . $ct);

if (empty($ct)) {
    $ct = 'no type';
}

if (isset($_GET['dw'])) {
    echo "document.writeln('Content-Type: $ct works!&lt;br&gt;');";
}
else if (isset($_GET['id'])) {
    $id = preg_replace('/[^a-z_]/', '', $_GET['id']);
    echo &lt;&lt;&lt;EOT
try {
    document.getElementById('{$id}').innerHTML
        = 'Content-Type: {$ct} works!';
}
catch (e) {
    alert("Couldn't find id of {$id}");
}
EOT;
}
else {
    die("// Nothing to do");
}</code></pre>
<p>So this allows me to inject the scripts like so:</p>
<pre><code>&lt;script src="js.php?ct=application/javascript&#038;todo"&gt;&lt;/script&gt;</code></pre>
<p>And they will set the HTTP Content-Type headers for external &lt;script&gt;s and do some stuff.</p>
<p>I also added data URIs, dynamic script <i>creation</i> and dynamic script <i>injection</i> (subtly different).</p>
<p>Data URIs scripts look like this:</p>
<pre><code>&lt;script src="data:X/Y,document.write('oh%20hai!')%3B"&gt;&lt;/script&gt;</pre>
<p></code></p>
<p>The dynamic script <i>creation</i> I'm doing looks like this:</p>
<pre><code>window.onload = function () {
    var c = document.createElement('script');
    c.innerHTML = '// do something in JS!';
    document.body.appendChild(s);
</code></pre>
<p>And dynamic script <i>injection</i> looks like this:</p>
<pre><code>    var i = document.createElement('script');
    i.src = 'js.php?do=something';
    document.body.appendChild(i);
};
</code></pre>
<h3>Results</h3>
<p><b>NOTE</b>: I will be switching this to use <a href="http://www.browserscope.org/">Browserscope</a> sooner or later, but for now the results of my very manual testing can be seen below.</p>
<p><iframe width="800" height="600" frameborder='0' src='https://spreadsheets.google.com/spreadsheet/pub?hl=en&#038;hl=en&#038;key=0AoMxlrkZCQVadGJHMktISTJNMDJwU3BTZ3N5YjBzanc&#038;single=true&#038;gid=0&#038;output=html&#038;widget=true'></iframe></p>
<h3>Conclusions / Findings</h3>
<p>So, some interesting things I found out from this were:</p>
<style type="text/css">
ol li { margin-bottom: 20px; }
</style>
<ol>
<li>Though IE8 supports data URIs in other areas (supposedly), it will <b>not execute a &lt;script&gt; with a data URI as the <code>src</code> attribute</b> (verified by <a href="http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/ie9-beta-minor-change-list.aspx">Microsoft here</a>).  This has been changed in IE9.  Go nuts.
<li>IE9 handles data URI encoding much more strictly than other browsers.  Without properly encoding various parts of the inline data (i.e. <code>/</code> -> <code>%2F</code>, <code>;</code> -> <code>%3B</code>) &lt;scripts&gt; will not execute nor give any particular reason why they didn't (as far as I could find).  At first this lead me to believe that data URIs in &lt;script&gt; <code>src</code>s weren't working in IE8 or IE9 at all!</li>
<li>IE9 accepts many different type attributes on &lt;script&gt; tags like other "good" browsers.  This is a large jump above IEs 6-8, <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>A browser made by <a href="http://www.microsoft.com/presspass/inside_ms.mspx#RevenueHeadcount">90,000 geeks over 30 years</a> is now being rivaled by the browser I have in my pocket on my phone (OK, that's not fair - Apple and Google both made Webkit &amp; Chrome).</li>
</ol>
<p>As always, let me know if you find problems with my results or if you want to contribute some results yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://danbeam.org/blog/2011/05/16/2295-script-tags-later/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Script: not a type-ical tag</title>
		<link>http://danbeam.org/blog/2011/05/06/script-not-a-type-ical-tag/</link>
		<comments>http://danbeam.org/blog/2011/05/06/script-not-a-type-ical-tag/#comments</comments>
		<pubDate>Fri, 06 May 2011 07:08:58 +0000</pubDate>
		<dc:creator>danbeam</dc:creator>
				<category><![CDATA[Compatibility]]></category>
		<category><![CDATA[Cross-browser]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[x-javascript]]></category>

		<guid isPermaLink="false">http://danbeam.org/blog/?p=10</guid>
		<description><![CDATA[Problem I was talking to Paul Irish today regarding some tweaks I was doing to html5boilerplate&#8216;s code when I hit the usual kludge you see when dealing with JavaScript in .htaccess files or &#60;VirtualHost&#62; directives. Something to the effect of &#8230; <a href="http://danbeam.org/blog/2011/05/06/script-not-a-type-ical-tag/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Problem</h3>
<p>I was talking to <a href="http://paulirish.com" target="_blank">Paul Irish</a> today regarding <a href="https://github.com/paulirish/html5-boilerplate/pull/485/files" target="_blank">some tweaks</a> I was doing to <a href="http://html5boilerplate.com" target="_blank">html5boilerplate</a>&#8216;s code when I hit the usual kludge you see when dealing with JavaScript in <code>.htaccess</code> files or <code>&lt;VirtualHost&gt;</code> directives.  Something to the effect of<br />
<code>
<pre># compress JavaScript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# [ ... snip ... ]
FilterProvider  COMPRESS  DEFLATE resp=Content-Type
                         /(text/|(application/(x-)?)javascript)/
# [ ... snip ... ]
# add expires to JavaScript
ExpiresByType application/javascript    "access plus 2 months"
ExpiresByType application/x-javascript  "access plus 2 months"
ExpiresByType text/javascript           "access plus 2 months"</pre>
<p></code></p>
<p>And I wondered why we, as developers, stand for using JavaScript with up to 3 mime/content-types when it was clearly <i><b>specified 5 years ago</b></i> in <a href="http://tools.ietf.org/html/rfc4329#section-7.2" target="_blank">RFC 4329</a> that we&#8217;d at least like to use only one?!</p>
<p>From that spec:<br />
<code>
<pre>Use of the "text" top-level type for this kind of content is
known to be problematic.  This document thus defines
text/javascript and text/ecmascript but marks them as
"obsolete".  Use of experimental and unregistered media
types, as listed in part above, is discouraged. The media
types,

   * application/javascript
   * application/ecmascript

which are also defined in this document, are intended for
common use and should be used instead.</pre>
<p></code></p>
<p>I know that this is an informational RFC, not a standards track one, but I wanted to see how close modern (and not so modern) browsers were doing at accomplishing this goal of allowing external script files with the <code>Content-Type: application/javascript</code>.</p>
<h2>Test</h2>
<p>So, I threw together a <a href="/script-type-test/">test page</a> to check how server-side <code>Content-Type</code> HTTP headers and <code>&lt;script type="attributes"&gt;</code> affected their execution.  Here&#8217;s how I set up the types with Apache on my web server:<br />
<code>
<pre>AddType application/javascript      .aj
AddType application/x-javascript    .axj
AddType text/javascript             .tj
AddType zomg/totally-fake           .ztf
</pre>
<p></code><br />
And then I created a file with each of those extensions with a unique message that would <code>document.write</code> itself to my test page if they were execute correctly.  Here&#8217;s the basic gist of the test page:<br />
<code>
<pre>&lt;h1&gt;With type="XXX/YYY":&lt;/h1&gt;
&lt;script type="XXX/YYY" src="write.aj"&gt;&lt;/script&gt;
&lt;script type="XXX/YYY" src="write.axj"&gt;&lt;/script&gt;
&lt;script type="XXX/YYY" src="write.tj"&gt;&lt;/script&gt;
&lt;script type="XXX/YYY" src="write.ztf"&gt;&lt;/script&gt;</pre>
<p></code><br />
And I also added a test with <code>&lt;script&gt;</code> tags with no type attribute at all, as per past advice I remember hearing from <a href="http://javascript.crockford.com/script.html" target="_blank">Doug Crockford&#8217;s site</a>.</p>
<h3>Results</h3>
<p>Here were my results in a nifty table format (X = it worked!):</p>
<table cellspacing="0" cellpadding="3" border="0">
<tr>
<th width="89"></th>
<th align="center" colspan="20">&lt;script type&gt;</th>
</tr>
<tr>
<th></th>
<th colspan="4" width="89">application<br />/javascript</th>
<th colspan="4" width="89">application<br />/x-javascript</th>
<th colspan="4" width="89">text<br />/javascript</th>
<th colspan="4" width="89">zomg<br />/totally-fake</th>
<th colspan="4" width="111">(none)</th>
</tr>
<tr>
<th>Browser</th>
<th>.aj</th>
<th>.axj</th>
<th>.tj</th>
<th>.ztf</th>
<th>.aj</th>
<th>.axj</th>
<th>.tj</th>
<th>.ztf</th>
<th>.aj</th>
<th>.axj</th>
<th>.tj</th>
<th>.ztf</th>
<th>.aj</th>
<th>.axj</th>
<th>.tj</th>
<th>.ztf</th>
<th>.aj</th>
<th>.axj</th>
<th>.tj</th>
<th>.ztf</th>
</tr>
<tr>
<th>IE 6 (XP)</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>IE 7 (XP)</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>IE 8 (XP)</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>IE 9 (W7)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Safari 3 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Safari 4 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Safari 5 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Opera 8 (XP)</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Opera 9 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Opera 10 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Opera 11 (W7)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Opera 11 (Ubuntu)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>FF 2 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>FF 3 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>FF 3.6 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>FF 3.6 (Ubuntu)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>FF 4 (W7)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>FF 4 (Linux)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Chrome 11 (XP)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Chrome 11 (W7)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
<tr>
<th>Chromium 11 (Ubuntu)</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>X</th>
<th>X</th>
<th>X</th>
<th>X</th>
</tr>
</table>
<h3>Conclusion</h3>
<p>So, given this data, I came to one very clear conclusion:<br />
<b>never use &lt;script type=&#8221;zomg/totally-fake&#8221;&gt;</b> <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .</p>
<p>In addition to this epiphany, I plan only serving my JavaScript with <b>one <code>Content-Type</code> &#8211; <code>application/javascript</code></b> as it had absolutely no impact on anything and is the right thing to do <sup>TM</sup> for the open web.</p>
<p>I&#8217;m also going to simply <b>omit <code>type="XXX/YYY"</code></b> from my markup <i>when I&#8217;m not validating my page as XHTML 1.0</i>, as it saves bytes and works the same way (yup, even in HTML5).  I do have a few sites that are valid XHTML 1.0, so it <i>does matter</i> in those cases, so in those cases I&#8217;ll use <b><code>type="text/javascript"</code></b> so I can continue passing and working in every browser possible.</p>
<p>Will you do the same? <img src='http://danbeam.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Update:</h3>
<p>I tested quite a few more combinations and wrote a follow-up article about a couple more things I found out <a href="/blog/2011/05/2295-script-tags-later/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danbeam.org/blog/2011/05/06/script-not-a-type-ical-tag/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

