<?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:atom="http://www.w3.org/2005/Atom"
				  >
<channel>
<title></title>
<link>http://mattsnider.com/</link>
<description><![CDATA[Understanding Web Development]]></description>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://mattsnider.com/feed" type="application/rss+xml" />
<item>
<title>Updated YUI3 for YUI2</title>
<link>http://mattsnider.com/javascript/updated-yui3-for-yui2/</link>
<guid isPermaLink="true" >http://mattsnider.com/javascript/updated-yui3-for-yui2/</guid>
<pubDate>Thu, 02 Sep 2010 09:47:58 -0700</pubDate>
<description><![CDATA[<p>For those of you who are using my YUI 3 for YUI 2 emulation code, I want to share with you the latest, and perhaps final version. This version is very similar to what we are now using on <a href="http://www.mint.com">Mint.com</a>, where I have been successfully swapping back and forth between the mock YUI 3 and the real YUI 3.</p>

<p><a href="http://yui-ext-mvc.googlecode.com/svn/trunk/assets/js/yahoo-ext/yui3foryui2.js">http://yui-ext-mvc.googlecode.com/svn/trunk/assets/js/yahoo-ext/yui3foryui2.js</a></p>

<p><h3>Notes</h3></p>
<p><ul>
<li>Y.Base.create has been added</li>
<li>use YUI.add instead of YUI().add</li>
<li>Y.NodeList is now supported</li>
<li>Y.Event.attach and Y.Event.detach emulated</li>
<li>window resize event supported</li>
<li>the Y.mix function is fully emulated</li>
</ul></p>

<p>There is definitely more, but the above is a good list of the major improvements.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=537</wfw:commentRss>
</item>
<item>
<title>Web Development News August 2010 B</title>
<link>http://mattsnider.com/news/web-development-news-082010-b/</link>
<guid isPermaLink="true" >http://mattsnider.com/news/web-development-news-082010-b/</guid>
<pubDate>Tue, 31 Aug 2010 10:10:59 -0700</pubDate>
<description><![CDATA[<p>Here are some interesting articles from the first half of August:</p>

<p><h3>JavaScript</h3></p>
<p>Douglas Crockford continues his series on the state of JavaScript, talking about the role of event loops and server-side JavaScript. This is a must watch for web developers:</p>

<p><div><object width="576" height="324"><param name="movie" value="http://d.yimg.com/m/up/ypp/default/player.swf"></param><param name="flashVars" value="vid=21663596&"></param><param name="allowfullscreen" value="true"></param><param name="wmode" value="transparent"></param><embed width="576" height="324" allowFullScreen="true" src="http://d.yimg.com/m/up/ypp/default/player.swf" type="application/x-shockwave-flash" flashvars="vid=21663596&"></embed></object></div></p>

<p><h3>Libraries</h3></p>

<p>Reid Burke has built a new command line, cross-browser testing framework for YUI, called Yeti. Yeti uses NodeJs to execute YUI tests against your code locally, before you commit your code to a shared repository. Find out more at:</p>

<p><a href="http://www.yuiblog.com/blog/2010/08/25/introducing-yeti-the-yui-easy-testing-interface/">http://www.yuiblog.com/blog/2010/08/25/introducing-yeti-the-yui-easy-testing-interface/</a></p>

<p>YUI announces a security patch to YUI 3.1. There was a security hole in there "io.swf" file that has been address. If you are using XDR then please read:</p>

<p><a href="http://www.yuiblog.com/blog/2010/08/19/yui-3-1-2/">http://www.yuiblog.com/blog/2010/08/19/yui-3-1-2/</a></p>

<p><h3>Personal</h3></p>

<p>I will be leaving Mint at the end of this week to join another startup. My time at Mint has been amazing, and we have built web UIs that most people thought impossible. I enjoyed working with the Mint team, but am looking forward to my next big startup. I'll let you all know where I am going next soon. </p>

<p>However, I can let you know my technology choices: Django as my MVC, Apache as my webserver, and Git for version control. We are experimenting with other technologies as well so that we can implement a continuous build process.</p>

<p>I'll keep everyone posted as to how things are going. We are looking for a strong back-end engineer to help with MySQL, Python, scaling, and more if you or someone you know might be interested.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=536</wfw:commentRss>
</item>
<item>
<title>Adding Find() to NodeList in YUI3</title>
<link>http://mattsnider.com/javascript/adding-find-to-nodelist-in-yui3/</link>
<guid isPermaLink="true" >http://mattsnider.com/javascript/adding-find-to-nodelist-in-yui3/</guid>
<pubDate>Tue, 24 Aug 2010 10:06:15 -0700</pubDate>
<description><![CDATA[<p>In YUI 3, when searching an array for a value, you have to include the <q>collection</q> module, as the <code>Y.Array.find()</code> function is not built into <code>Y.Array</code>. This is a little annoying, because 9 out of 10 times, I include the <q>collection</q> module, it is just for the <code>Y.Array.find()</code> function. Additionally, because the function isn't built into the core library, it is not used or added to the core features, like NodeList. Yet, I believe having a <code>find()</code> function on NodeList is very useful and this article provides a simply way to augment NodeList.</p>

<p><h3>How to do it&hellip;</h3></p>
<p><pre class="brush:js">Y.NodeList.prototype.find = function(fn) {
	var elNode;
	
	if (this.size()) {
		 elNode = Y.Array.find(this._nodes, function(elem) {
			return fn(new Y.Node(elem));
		});
	}
		
	return elNode ? new Y.Node(elNode) : elNode;
};</pre></p>

<p><h3>How it works&hellip;</h3></p>
<p>First, this augmentation is dependent on the <q>node</q> and <q>collection</q> modules; so make sure you include them or set this up as a module that requires those two. A NodeList instances has a protected property, <code>_node</code>, that is an array of all the native DOM elements in the NodeList, which can be passed into the <code>Y.Array.find</code> function. This then calls an anonymous function on each element in the <code>_node</code> array, which re-wraps the node with <code>Y.Node</code>, before passing it into the provided evaluation function. If the evaluation function returns <code>true</code>, then the <code>Y.Array.find</code> function stops and the HTML element is return. Otherwise, it will be <code>undefined</code>. The found node then needs to be wrapped by <code>Y.Node</code> again before returning and now you have a <code>find()</code> function for all your NodeList instances.</p>

<p><h3>There's more</h3></p>
<p>If you can use a selector to find the node you are looking for than the <code>filter()</code> function of NodeList is a better choice. Additinionally, NodeList has a <code>some()</code> that could be forced to behave like a find operation by passing in the output array as the context. However, I believe that adding another simple function is a better approach.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=535</wfw:commentRss>
</item>
<item>
<title>Web Development News August 2010 A</title>
<link>http://mattsnider.com/news/web-development-news-082010-a/</link>
<guid isPermaLink="true" >http://mattsnider.com/news/web-development-news-082010-a/</guid>
<pubDate>Wed, 18 Aug 2010 10:43:09 -0700</pubDate>
<description><![CDATA[<p>Not a whole lot of news this week, which is great because I had surgery on my left hand and typing one handed is a pain. Besides the articles included here, there was a lot of talk on whether to HTML validate your code or not. I'd say the general consensus was no, because of lack of ARIA support and the inability to add meta attributes. All browsers support meta-attributes, even if they aren't in the DTD and it is a better way to send data than hijacking existing attributes.</p>

<p>Here are some interesting articles from the first half of August:</p>

<p><h3>Browsers</h3></p>
<p>The latest version of IE9 is performing almost as well as the Chrome nightly, and nearly passes the Acid 2 tests. I think they Microsoft might finally be building a decent browser. Additionally, it supports opacity without the alpha filter:</p>

<p><a href="http://blogs.msdn.com/b/ie/archive/2010/08/04/html5-modernized-fourth-ie9-platform-preview-available-for-developers.aspx">http://blogs.msdn.com/b/ie/archive/2010/08/04/html5-modernized-fourth-ie9-platform-preview-available-for-developers.aspx</a></p>

<p><a href="http://www.quirksmode.org/">PPK</a> takes a serious stab at grading mobile browers. Take a look at his results:</p>

<p><a href="http://www.quirksmode.org/blog/archives/2010/08/first_serious_s.html">http://www.quirksmode.org/blog/archives/2010/08/first_serious_s.html</a></p>

<p><h3>JavaScript Libraries</h3></p>

<p><a href="http://www.jquery.com">jQuery</a> officially announces its plan to support mobile browsers:</p>

<p><a href="http://blog.jquery.com/2010/08/13/the-jquery-project-is-proud-to-announce-the-jquery-mobile-project/">http://blog.jquery.com/2010/08/13/the-jquery-project-is-proud-to-announce-the-jquery-mobile-project/</a></p>

<p>Caridy Patino wrote a nice YUI 3 gallery project to handle binding event handlers before the YUI 3 library has completely loaded. This is useful, so that user actions before the page is loaded are not lost:</p>

<p><a href="http://www.yuiblog.com/blog/2010/06/23/event-binder/">http://www.yuiblog.com/blog/2010/06/23/event-binder/</a></p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=534</wfw:commentRss>
</item>
<item>
<title>Clientside Moment Profiling</title>
<link>http://mattsnider.com/javascript/clientside-moment-profiling/</link>
<guid isPermaLink="true" >http://mattsnider.com/javascript/clientside-moment-profiling/</guid>
<pubDate>Thu, 12 Aug 2010 15:59:07 -0700</pubDate>
<description><![CDATA[<p>When developing complex JavaScript applications, it is useful to profile the loading of your pages, so you can better understand the bottlenecks of performance. To the end user, the most important moment is when the browser indicates that the page is finished loading. As developers, it is our job to understand why loading takes so long and how to improve it. Today's article will introduce a simple widget called MomentTracker, which allows you to easily compile a collection of important client-side moments and then output them.</p>

<p><h3>How to do it&hellip;</h3></p>
<p>Include the following snippet as the first element in your <code>head</code> element:</p>
<p><pre class="brush:js">var __momentTracker = {
	aMoments: [],

	addCookieHandler: function() {
		YAHOO.util.Event.on(window, 'unload', function() {
			var oneMinuteLater = new Date();
			oneMinuteLater.setTime((new Date()).getTime() + 60000);
			YAHOO.util.Cookie.set('__momentTracker', new Date(), {expires: oneMinuteLater});
		});
	},

	rollup: function() {
		var lastPageTime = YAHOO.util.Cookie.get('__momentTracker'),
			aMoments = __momentTracker.aMoments,
			rs = [],
			i, t1, t2;

		if (lastPageTime) {
			__momentTracker.lastPage = new Date(lastPageTime);
			aMoments.unshift('lastPage');
		}

		for (i=aMoments.length-1; 0<i; i-=1) {
			t1 = __momentTracker[aMoments[i-1]].getTime();
			t2 = __momentTracker[aMoments[i]].getTime();
			rs.unshift((t2-t1) + 'ms' + ' = ' + aMoments[i] + ' - ' + aMoments[i-1]);
		}

		return rs;
	},

	trackMoment: function(sName) {
		__momentTracker[sName] = new Date();
		__momentTracker.aMoments.push(sName);
	}
};
__momentTracker.trackMoment('pageStart');</pre></p>

<p>Then anytime you want to track an important moment, call the <code>trackMoment</code> function with the name you would like to call that moment:</p>

<p><pre class="brush:xml"><script type="text/javascript">__momentTracker.trackMoment('afterHTML');</script></pre></p>

<p>To measure the time between pages, we need to setup a cookie (call this anytime after <code>YAHOO.util.Cookie</code> and <code>YAHOO.util.Event</code> are included):</p>

<p><pre class="brush:js">__momentTracker.addCookieHandler();</pre></p>

<p>And lastly, to output the results call:</p>
<p><pre class="brush:js">Event.on(window, 'load', function() {
	__momentTracker.trackMoment('afterJavaScript');
	Y.log(__momentTracker.rollup().join("\n"));
});</pre></p>

<p><h3>How it works&hellip;</h3></p>
<p>The <code>trackMoment</code> function simply stores a date object, at the moment it is executed. The <code>addCookieHandler</code> function adds an unload event to record when the user leaves the page. The <code>rollup</code> function iterates on all the moments, calculates the difference between them in milliseconds, and then returns the results.</p>

<p>The implementation in this article, uses the YUI Logger module to print the results. However, you could modify the <code>rollup</code> function to suit your needs, and use the results in a more meaningful way. At <a href="http://www.mint.com">Mint.com</a> we pass the tracked moments times to the server, where they are aggregated into our performance monitoring system.</p>

<p>I've put together a quick <a href="http://www.mattsnider.com/tests/test_dataMomentTracking.html">demo page</a> to show it working.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=533</wfw:commentRss>
</item>
<item>
<title>Web Development News July 2010 B</title>
<link>http://mattsnider.com/news/web-development-news-072010-b/</link>
<guid isPermaLink="true" >http://mattsnider.com/news/web-development-news-072010-b/</guid>
<pubDate>Wed, 04 Aug 2010 09:43:21 -0700</pubDate>
<description><![CDATA[<p>Here is a roundup of some of the interesting news released during the later half of July.</p>

<p><h3>JavaScript</h3></p>

<p>Nokia has put together a best practices performance guide. This is especially useful for mobile developers, but the optimizations will improve performance in all browsers. It is very thorough:</p>

<p><a href="http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices">http://wiki.forum.nokia.com/index.php/JavaScript_Performance_Best_Practices</a></p>

<p>Google has released its JavaScript coding guidelines. Most of it is a collection of well-known best practices, but I found the JavaScript Types and JSDoc section to be particularly useful:</p>

<p><a href="http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml">http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml</a></p>

<p><a href="http://www.nczonline.net/">Nicholas Zakas</a> explores the various ways to detect if properties exist on objects and reveals the best ways to evaluate property existence:</p>

<p><a href="http://www.nczonline.net/blog/2010/07/27/determining-if-an-object-property-exists/">http://www.nczonline.net/blog/2010/07/27/determining-if-an-object-property-exists/</a></p>

<p><h3>HTML 5 & CSS 3</h3></p>

<p><a href="http://www.davidflanagan.com">David Flanagan</a> has written Canto, a improved HTML Canvas API. While it doesn't add a lot of new functionality, it does make working with Canvas elements a lot simpler:</p>

<p><a href="http://www.davidflanagan.com/2010/07/cantojs-an-impr.html">http://www.davidflanagan.com/2010/07/cantojs-an-impr.html</a></p>

<p><h3>Mobile</h3></p>

<p>Samsung's relatively new phone, the Wave, comes with a new WebKit based browser, Dolfin. <a href="http://www.quirksmode.org/">PPK</a> took some time to evaluate it:</p>

<p><a href="http://www.quirksmode.org/blog/archives/2010/07/new_kid_on_the.html">http://www.quirksmode.org/blog/archives/2010/07/new_kid_on_the.html</a></p>

<p><h3>Libraries</h3></p>

<p>Dojo has released version 1.5 with tons of improvements, including better mobile support:</p>

<p><a href="https://www.dojotoolkit.org/reference-guide/releasenotes/1.5.html">https://www.dojotoolkit.org/reference-guide/releasenotes/1.5.html</a></p>

<p>YUI has released a preview candidate for version 3.2.0. It includes a lot of nice improvements, but most notably is the mobile support:</p>

<p><a href="http://www.yuiblog.com/blog/2010/07/26/3-2-0pr1/">http://www.yuiblog.com/blog/2010/07/26/3-2-0pr1/</a></p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=532</wfw:commentRss>
</item>
<item>
<title>Using Data URIs</title>
<link>http://mattsnider.com/css/using-data-uris/</link>
<guid isPermaLink="true" >http://mattsnider.com/css/using-data-uris/</guid>
<pubDate>Thu, 29 Jul 2010 10:28:29 -0700</pubDate>
<description><![CDATA[<p>After reading Nicolas Zakas article, <a href="http://www.nczonline.net/blog/2010/07/06/data-uris-make-css-sprites-obsolete/">Data URIs make CSS sprites obsolete</a>, I was inspired to see how easy it would be to put into practice. His CSSEmbed JAR uses Base64 encoding for data URIs and <a href="http://en.wikipedia.org/wiki/MHTML">MHTML</a> to be backwards compatible with IE 6 and 7. So the logical step was to create a build script that runs CSSEmbed against all my CSS files.</p>

<p><h3>Getting ready</h3></p>

<p>You will need to install a copy of <a href="http://ant.apache.org/">ant</a> and <a href="http://sourceforge.net/projects/ant-contrib/files/">ant-contrib</a> to use these build scripts. To include ant-contrib into your ant build script, use:</p>

<p><pre class="brush:xml">
&lt;taskdef resource="net/sf/antcontrib/antlib.xml" classpath="pathToJar/ant-contrib-1.0b3.jar"/&gt;</pre></p>

<p>Additionally, you will need the <a href="http://github.com/downloads/nzakas/cssembed/cssembed-0.3.3.jar">CSSEmbed JAR</a>.</p>

<p><h3>How to do it&hellip;</h3></p>

<p>First setup some properties to be used by the ant target:</p>

<p><pre class="brush:xml">&lt;property name="datauri.jar" value="pathToCSSEmbed/cssembed-0.3.3.jar"/&gt;
&lt;property name="datauri.charset" value="UTF-8"/&gt;
&lt;property name="datauri.inputdir" value="inputDirectory"/&gt;
&lt;property name="datauri.mhtmlroot" value="URLofCSSorDomain"/&gt;
&lt;property name="datauri.outputdir" value="outputDirectory"/&gt;
&lt;property name="datauri.root" value="URLofCSSorDomain"/&gt;</pre></p>

<p>Next create your ant target:</p>

<p><pre class="brush:xml">&lt;target name="create.css.datauri"&gt;
	&lt;for param="file"&gt;
		&lt;fileset dir="${datauri.inputdir}" id="css.datauri.files"&gt;
			&lt;include name="*.css"/&gt;
		&lt;/fileset&gt;
		&lt;sequential&gt;
			&lt;propertyregex property="datauri.filename" input="@{file}" regexp="(\w+\.css)" select="\1" override="true"/&gt;
			&lt;echo message="converting ${datauri.filename} to datauri"/&gt;
			&lt;java jar="${datauri.jar}" fork="true" failonerror="true"&gt;
				&lt;arg value="-o" /&gt;
				&lt;arg value="${datauri.outputdir}/${datauri.filename}" /&gt;
				&lt;arg value="--charset" /&gt;
				&lt;arg value="${datauri.charset}" /&gt;
				&lt;arg value="--root" /&gt;
				&lt;arg value="${datauri.root}" /&gt;
				&lt;arg value="@{file}" /&gt;
			&lt;/java&gt;
			&lt;java jar="${datauri.jar}" fork="true" failonerror="true"&gt;
				&lt;arg value="-o" /&gt;
				&lt;arg value="${datauri.outputdir}/ie-${datauri.filename}" /&gt;
				&lt;arg value="--mhtml" /&gt;
				&lt;arg value="--mhtmlroot" /&gt;
				&lt;arg value="${datauri.mhtmlroot}" /&gt;
				&lt;arg value="--charset" /&gt;
				&lt;arg value="${datauri.charset}" /&gt;
				&lt;arg value="@{file}" /&gt;
			&lt;/java&gt;
		&lt;/sequential&gt;
	&lt;/for&gt;
&lt;/target&gt;</pre></p>

<p><h3>How it works&hellip;</h3></p>

<p>The trickiest part when using CSSEmbed is the <code>root</code> and <code>mhtmlroot</code> properties. These URLs are not the location of the files on your computer, but on the web, and varies depending on how you reference the images in your CSS. If the images are relative to your CSS, then the values should be set to the URL of your CSS directory. If the images are relative to the root of your domain, then these values should be your URL of your root domain. CSSEmbed will make JAVA net calls when generating the URIs.</p>

<p>The ant-contrib project was necessary, because basic ant does not have a way to iterate on a <code>fileset</code>. I tried to simulate this using macros, but couldn't get it working correctly, so I settled on using ant-contrib. </p>

<p>In the build target, the <code>for</code> iterates on the <code>fileset</code> of CSS files in your CSS directory, storing the value as the param <code>@{file}</code>. As written, it will only search that immediate directory, and not subdirectories. To search subdirectories as well, change <code>*.css</code> to <code>**/*.css</code>.</p>

<p>The <code>propertyregex</code> task finds the filename of the file, by removing the absolute path from <code>@{file}</code>. The CSSEmbed JAR is executed twice: once to create the non-IE CSS and a second time to create the IE 6 & 7 CSS. Your code will need to branch serving a different file depending on the browser. You can do this client-side using conditional comments:</p>

<p><pre class="brush:xml">&lt;link type="text/css" href="/build/css/dataUriTest.css" rel="stylesheet"/&gt;
&lt;!--[if lt IE 8]&gt;
	&lt;link type="text/css" href="pathToCSS/ie-dataUriTest.css" rel="stylesheet"/&gt;
&lt;![endif]--&gt;</pre></p>

<p>However, this is less efficient than branching server-side, because the IE version contains all the same CSS as the non-IE version (only the URIs vary).</p>

<p><h3>What's next?</h3></p>
<p>I ran out of time while writing this article, but I would have liked to write a build step that strips out all CSS rules from the IE version, except those that contain data URIs. This would reduce the overhead of client-side branching, using conditional comments. However, the most efficient way of branching would still be server-side, as the data URIs would be duplicated in any client-side branching system.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=531</wfw:commentRss>
</item>
<item>
<title>Web Development News July 2010 A</title>
<link>http://mattsnider.com/news/web-development-news-072010-a/</link>
<guid isPermaLink="true" >http://mattsnider.com/news/web-development-news-072010-a/</guid>
<pubDate>Thu, 22 Jul 2010 10:55:11 -0700</pubDate>
<description><![CDATA[<p>Here is a roundup of some of the interesting news released at the beginning of July.</p>

<p><h3>HTML 5 & CSS 3</h3></p>

<p>Using HTML 5's local storage system <a href="http://www.dustindiaz.com/">Dustin Diaz</a> provides a widget to handle client-side caching:</p>

<p><a href="http://www.dustindiaz.com/javascript-cache-provider/">http://www.dustindiaz.com/javascript-cache-provider/</a></p>

<p><a href="http://www.nczonline.net">Nicholas Zakas</a> discusses using data URLs in your CSS, making spriting obsolete. Data URLs add the images to the CSS payload, so the browser doesn't have to make additional requests for images. It's supported by modern browsers and is better than spriting:</p>

<p><a href="http://www.nczonline.net/blog/2010/07/06/data-uris-make-css-sprites-obsolete/">http://www.nczonline.net/blog/2010/07/06/data-uris-make-css-sprites-obsolete/</a></p>

<p><h3>Other</h3></p>

<p>Have you ever forgot to include the value of a <code>src</code> attribute on your page, causing the browser to fetch the index page of the current directory, or worse repost the previous request? You'll be happy to know that browsers are working on preventing this. <a href="http://www.nczonline.net">Nicholas Zakas</a> discusses the status of the way major browsers are handling empty <code>src</code> attributes:</p>

<p><a href="http://www.nczonline.net/blog/2010/07/13/empty-string-urls-browser-update/">http://www.nczonline.net/blog/2010/07/13/empty-string-urls-browser-update/</a></p>

<p>Another article by <a href="http://www.dustindiaz.com/">Dustin Diaz</a> describing how to do client-side fuzzy-matching with autocomplete widgets. This is a much needed improvement to most autocompletes and I strongly recommend checking this out:</p>

<p><a href="http://www.dustindiaz.com/autocomplete-fuzzy-matching/">http://www.dustindiaz.com/autocomplete-fuzzy-matching/</a></p>

<p>Another great article from <a href="http://www.nczonline.net">Nicholas Zakas</a> discussing ways to improve JavaScript minification. Much of this I've discussed previously, but this is a quick read and a good refresher:</p>
<p><a href="http://www.alistapart.com/articles/javascript-minification-part-II/">http://www.alistapart.com/articles/javascript-minification-part-II/</a></p>

<p><a href="http://blog.stevenlevithan.com/">Steve Levithan</a> wrote a cool JavaScript regular expression syntax highlighter, using JavaScript. This could be useful for debugging your code, and maybe moreso, if you are including Regular expressions in your blog:</p>

<p><a href="http://stevenlevithan.com/regex/syntaxhighlighter/">http://stevenlevithan.com/regex/syntaxhighlighter/</a></p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=530</wfw:commentRss>
</item>
<item>
<title>Event Based Cross Site Scripting Attack</title>
<link>http://mattsnider.com/javascript/event-based-cross-site-scripting-attack/</link>
<guid isPermaLink="true" >http://mattsnider.com/javascript/event-based-cross-site-scripting-attack/</guid>
<pubDate>Wed, 14 Jul 2010 11:21:52 -0700</pubDate>
<description><![CDATA[<p>I recently ran into a devious XSS attack, based on the <code>onerror</code> event. It can be done by exploiting other events as well, but the <code>onerror</code> event works particularly well, because the JavaScript is executed right as the node is rendered or appended to the page. Here is the attack:</p>

<p><pre class="brush:xml">&lt;img onerror=alert('x'); src=f</pre></p>

<p>Then when the user content is appended or rendered in the page, the JavaScript executes. Replacing the <code>alert</code> statement with a malicious script, such as reading or changing cookies, is how the attack works. When the <code>img</code> element is rendered it throws the <code>onerror</code> event in browsers that support it, because the markup is incomplete. The especially tricky thing about this attack is most of HTML removal regular expressions used to sanitize parameters won't catch this attack, because there is no closing tag.</p>

<p>To ensure you are not susceptible to this attack, always ensure you are escaping HTML entities before writing to the database, and then do not unescaping them before appending text to the document.</p>

<p>For more information about all cross site scripting attacks, see <a href="http://ha.ckers.org/xss.html">http://ha.ckers.org/xss.html</a>.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=529</wfw:commentRss>
</item>
<item>
<title>Simple JavaScript Function To Include CSS</title>
<link>http://mattsnider.com/javascript/simple-javascript-function-to-include-css/</link>
<guid isPermaLink="true" >http://mattsnider.com/javascript/simple-javascript-function-to-include-css/</guid>
<pubDate>Thu, 08 Jul 2010 11:00:11 -0700</pubDate>
<description><![CDATA[<p>This article explains how to write a simple JavaScript function to include CSS files and notify when the loading of the file is complete. The issue is that most browsers do not fire a <code>load</code> event when the <code>link</code> element finishes processing the included CSS rules. And while many libraries have mechanisms for notifying when the CSS is included, I believe this technique is lighter and more elegant. A special thanks goes out to the UX team at <a href="http://www.facebook.com">Facebook.com</a> who first described this technique to me.</p>

<p><h3>How to do it&hellip;</h3></p>

<p>The JavaScript function you will need is:</p>
<p><pre class="brush:js">function includeCSS(conf) {
	if (! (conf && conf.href && conf.name && conf.fx)) {
		throw new Error("Missing configuration for includeCSS functions.");
	}
	
	var pfx = conf.prefix || 'js_',
		id = pfx + conf.id,
		elEvalNode = document.createElement('div'),
		elLinkNode = document.createElement('link'),
		iIntervalId;

	if (includeCSS.oIncludedField[id] && ! conf.force) {return false;}
	includeCSS.oIncludedField[id] = true;

	// setup eval node
	elEvalNode.id = id;
	elEvalNode.visiblity = 'hidden';
	elEvalNode.className = conf.className;
	includeCSS.elBody.appendChild(elEvalNode);

	// setup link node
	elLinkNode.charset = conf.charset || "utf-8";
	elLinkNode.href = conf.href;
	elLinkNode.rel = "stylesheet";
	elLinkNode.type = "text/css";
	includeCSS.elHead.appendChild(elLinkNode);

	// start polling
	iIntervalId = setInterval(function() {
		if (0 &lt; elEvalNode.offsetHeight) {
			clearInterval(iIntervalId);
			elEvalNode.parentNode.removeChild(elEvalNode);
			conf.fx.call(conf.ctx || this, conf.id, conf.data);
		}
	}, 250);

	return true;
}

// some global variables used by the function
includeCSS.elBody = document.getElementsByTagName("body")[0];
includeCSS.elHead = document.getElementsByTagName("head")[0];
includeCSS.oIncludedField = {};</pre></p>

<p>An example CSS files would be something like the following:</p>
<p><pre class="brush:css">body {
	background-color: #333;
	color: #F00;
}

p {
	font-size: 120%;
}

a {
	color: #900;
}

h1 {
	font-variant: small-caps;
}

.actions {
	background-color: #999;
	border: 1px solid #666;
}

.copy {
	color: #C33;
}

/* this style notifies the JavaScript that file is loaded
and should be the last rule in the CSS file */

#js_myCSSFileName {
	height: 10px;
}</pre></p>

<p>Then to actually use the include function call:</p>
<p><pre class="brush:js">function handleCallback(sId, oData) {
	alert("The CSS file (" + sId + ") has finished loading.");
}
if (! includeCSS({href:'pathToFile/myCSSFileName.css', id:'myId', fx:handleCallback})) {
	alert('CSS file (' + sFileName + ') is already included.');
}</pre></p>

<p><h3>How it works&hellip;</h3></p>
<p>The JavaScript function requires a single configuration object as its only argument. This object must have the <code>href</code>, <code>id</code>, and <code>fx</code> properties defined, and may optionally define <code>prefix</code>, <code>className</code>, <code>charset</code>, <code>ctx</code>, and <code>data</code>. The <code>href</code> property is the location of the CSS file to include, the <code>id</code> property is the name for the rule you will be using to determine that the CSS has finished loading, and the <code>fx</code> property is the success callback function. The <code>prefix</code> property is defaulted to <code>js_</code> and is the prefix to apply to the <code>id</code> property for the notifying CSS rule. The <code>className</code> property allows developers to specify a <code>className</code> that should be applied to the <code>div</code> element in case they need to remove global styles (like borders). The <code>charset</code> property defaults to <code>UTF-8</code> and is the character set used by the CSS file. The <code>ctx</code> property is the execution context of the callback function and the <code>data</code> property is an object to pass as the second argument to the callback function; both default to <code>undefined</code>.</p>

<p>When the <code>includeCSS</code> function is called it first checks to see if the CSS file has already been included using this function, returning <code>false</code> when it has and <code>true</code> when it has not been. If it has not been included, an empty <code>div</code> element is appended to the <code>body</code> element, and a <code>link</code> element is appended to the <code>head</code> element. The <code>link</code> element will cause the browser to begin downloading and evaluating the rules of the CSS file. The <code>div</code> element will have the <code>id</code> attribute of <code>js_idProperty</code> and a height of ZERO, because it lacks content. The last rule in the included CSS file needs to target the <code>div</code> element using <code>#js_idProperty</code> and adjust its height to something greater than ZERO. The last step of the <code>includeCSS</code> function is to start an interval callback to evaluate when the <code>div</code> element has a height greater than ZERO. When this happens the callback function is executed.</p>

<p>Putting it all together, the developer calls the <code>includeCSS</code> function, which fetches the CSS file and appends a <code>div</code> element to the page. The last rule of the CSS file should update the height of the appended <code>div</code> element, notifying the JavaScript that the CSS has finished loading. When this happens a callback function is executed and the developer is notified that their styles have completed loading and rendering. You can play with this function using the following test page:</p>

<p><a href="http://www.mattsnider.com/tests/test_cssInclude.html">Test Page</a></p>

<p><h3>There's more&hellip;</h3></p>
<p>Since a configuration object is used as the only argument to the <code>includeCSS</code> function, it is easy to augment. Probably the most needed augmentations are a <code>timeout</code> and a <code>failure</code> callback function. The former would fire if the interval hasn't finished after a specified amount of time and the latter would fire if the CSS file was not found.</p>

<p>One downside to this technique is it only works on CSS files under your control, since you have to be able to add a rule to the end of the CSS document. Although, it is not the most efficient solution, you can work around this issue by using a server-side proxy that fetches remote CSS and appends a rule to the end of the file.</p>]]></description>
<wfw:commentRss>http://js-kit.com/rss/mattsnider.com/p=528</wfw:commentRss>
</item>
</channel>
</rss>