<?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>MaisonBisson.com &#187; js</title>
	<atom:link href="http://maisonbisson.com/blog/post/tag/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://maisonbisson.com</link>
	<description>A bunch of stuff I would have emailed you about.</description>
	<lastBuildDate>Sat, 14 Nov 2009 20:14:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Detecting Broken Images in JavaScript</title>
		<link>http://maisonbisson.com/blog/post/12150/detecting-broken-images-in-javascript/</link>
		<comments>http://maisonbisson.com/blog/post/12150/detecting-broken-images-in-javascript/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 14:45:49 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[broken images]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[link rot]]></category>
		<category><![CDATA[onerror]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/?p=12150</guid>
		<description><![CDATA[
We&#8217;ve become accustomed to link rot and broken images in nearly all corners of the web, but is there a way to keep things a bit cleaner?
K.T. Lam of Hong Kong University of Science and Technology came up with this sweet trick using jQuery and readyState to find and replace broken images:

jQuery&#40;'span#gbs_'+info.bib_key&#41;.parents&#40;'ul'&#41;.find&#40;'img.bookjacket[@readyState*=&#34;uninitialized&#34;]'&#41;.replaceWith&#40;'&#60;img src=&#34;'+info.thumbnail_url+'&#34; alt=&#34;'+strTitle+'&#34; height=&#34;140&#34; [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-12150"><!-- &nbsp; --></abbr>
<p>We&#8217;ve become accustomed to link rot and broken images in nearly all corners of the web, but is there a way to keep things a bit cleaner?</p>
<p>K.T. Lam of Hong Kong University of Science and Technology came up with <a href="http://catalog.ust.hk/catalog/wp-content/plugins/scriblio/js/scrib.googlebook.js">this sweet trick</a> using jQuery and <code>readyState</code> to find and replace broken images:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span#gbs_'</span><span style="color: #339933;">+</span>info.<span style="color: #660066;">bib_key</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img.bookjacket[@readyState*=&quot;uninitialized&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img src=&quot;'</span><span style="color: #339933;">+</span>info.<span style="color: #660066;">thumbnail_url</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; alt=&quot;'</span><span style="color: #339933;">+</span>strTitle<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; height=&quot;140&quot; width=&quot;88&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And it works really well, but only in IE. Testing for <code>img.complete</code> or <code>img.naturalWidth</code> <a href="http://talideon.com/weblog/2005/02/detecting-broken-images-js.cfm">might be possibilities</a>, but I&#8217;m much more interested in the <code>onerror</code> property of the img tag:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;picture1.gif&quot;</span> <span style="color: #000066;">onerror</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;this.onerror=null;this.src='missing.gif';&quot;</span><span style="color: #339933;">/&gt;</span></pre></div></div>

<p>Or in JS:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> imgsrc <span style="color: #339933;">=</span> <span style="color: #3366CC;">'picture1.gif'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
img.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; can't be loaded.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
img.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; is loaded.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> imgsrc<span style="color: #339933;">;</span></pre></div></div>

<p>Or call a JS function when the browser detects a broken image:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> ImgError<span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	source.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;/images/noimage.gif&quot;</span><span style="color: #339933;">;</span>
	source.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://jquery.com/images/bibeault_cover150A.jpg&quot;</span>
border<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;1&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;100&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;image&quot;</span> <span style="color: #000066;">onerror</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;ImgError(this)&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>I haven&#8217;t tested any of this code, but it&#8217;s just a matter of time.</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/12150/detecting-broken-images-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Compress CSS &amp; JavaScript Using PHP Minify</title>
		<link>http://maisonbisson.com/blog/post/11994/compress-css-javascript-using-php-minify/</link>
		<comments>http://maisonbisson.com/blog/post/11994/compress-css-javascript-using-php-minify/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 12:50:13 +0000</pubDate>
		<dc:creator>Casey Bisson</dc:creator>
				<category><![CDATA[Dispatches]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[minify]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://maisonbisson.com/blog/post/11994/compress-css-javascript-using-php-minify</guid>
		<description><![CDATA[
It was part of a long thread among WordPress hackers over the summer and fall, but this post at VulgarisOverIP just reminded of it: minify promises to be an easy way to compress external CSS and JavaScript without adding extra steps to your develop/deploy process. No, really, look at the usage instructions. (To be clear, [...]]]></description>
			<content:encoded><![CDATA[<abbr class="unapi-id" title="maisonbisson-11994"><!-- &nbsp; --></abbr>
<p>It was part of a long thread among WordPress hackers over the summer and fall, but <a href="http://www.vulgarisoip.com/2007/06/21/minify-your-external-javascript-and-css-with-php/" title="“Minify” your external JavaScript and CSS with PHP at VulgarisOverIP">this post at VulgarisOverIP</a> just reminded of it: <a href="http://code.google.com/p/minify/">minify</a> promises to be an easy way to compress external CSS and JavaScript without adding extra steps to your develop/deploy process. No, really, look at <a href="http://code.google.com/p/minify/wiki/UserGuide" title="UserGuide - minify - Google Code">the usage instructions</a>. (To be clear, the Vulgaris and Google Code versions are different, one derived from the other and backported to PHP4 compatible. Still, the concept is the same.)</p>
<p>Vulgaris reports a nearly 300% decrease in time to download, definitely worth the effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://maisonbisson.com/blog/post/11994/compress-css-javascript-using-php-minify/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>