<?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>Derek Gathright &#187; Javascript</title>
	<atom:link href="http://www.derekville.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.derekville.net</link>
	<description>Scribbles &#38; Bits</description>
	<lastBuildDate>Fri, 18 Jun 2010 17:36:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Node-YQL</title>
		<link>http://www.derekville.net/2010/node-yql/</link>
		<comments>http://www.derekville.net/2010/node-yql/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 20:29:04 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://www.derekville.net/?p=676</guid>
		<description><![CDATA[The more I play around with Node.js, the more I love server-side JavaScript. Once you get over the weirdness of writing JavaScript outside of the browser, it feels very natural. And the bonus is that it is blazing fast. Also, &#8230; <a href="http://www.derekville.net/2010/node-yql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div align="center" style="float:left; padding:20px;"><img src="http://farm3.static.flickr.com/2601/3858500752_9c3a39e4af.jpg" height="200" /></div>
<p>The more I play around with <a href="http://nodejs.org/">Node.js</a>, the more I love server-side JavaScript.  Once you get over the weirdness of writing JavaScript outside of the browser, it feels very natural.  And the bonus is that it is blazing fast.  </p>
<p>Also, as I&#8217;ve been playing around with <a href="http://developer.yahoo.com/yql/">YQL</a> (Yahoo Query Language) more lately, I realized I wanted to be able to access YQL data from within my Node app.  So, I created a <a href="http://github.com/drgath/node-yql">node-yql </a> module.  </p>
<p>Now you can do something like&#8230;</p>
<div style="clear:both"></div>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YQL.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SELECT * FROM weather.forecast WHERE location=90066&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> location  <span style="color: #339933;">=</span> response.<span style="color: #660066;">query</span>.<span style="color: #660066;">results</span>.<span style="color: #660066;">channel</span>.<span style="color: #660066;">location</span><span style="color: #339933;">,</span>
	    condition <span style="color: #339933;">=</span> response.<span style="color: #660066;">query</span>.<span style="color: #660066;">results</span>.<span style="color: #660066;">channel</span>.<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">condition</span><span style="color: #339933;">;</span>
&nbsp;
	sys.<span style="color: #660066;">puts</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The current temperature in &quot;</span> <span style="color: #339933;">+</span> location.<span style="color: #660066;">city</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; is &quot;</span> <span style="color: #339933;">+</span> condition.<span style="color: #660066;">temp</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; degrees&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Output: The current temperature in Los Angeles is 57 degrees</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2010/node-yql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jsFiddle: A JavaScript playground</title>
		<link>http://www.derekville.net/2010/jsfiddle-a-javascript-playground/</link>
		<comments>http://www.derekville.net/2010/jsfiddle-a-javascript-playground/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 05:59:24 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jsfiddle]]></category>

		<guid isPermaLink="false">http://www.derekville.net/?p=669</guid>
		<description><![CDATA[Ajaxian had a story yesterday about a brand-new JavaScript playground called jsFiddle. A write and execute web-based JavaScript IDE is nothing new, but this is much, much more than that. The real power of jsFiddle is that you have the &#8230; <a href="http://www.derekville.net/2010/jsfiddle-a-javascript-playground/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ajaxian had <a href="http://ajaxian.com/archives/jsfiddle" target="_blank">a story</a> yesterday about a brand-new JavaScript playground called <a href="http://jsfiddle.net">jsFiddle</a>. A write and execute web-based JavaScript IDE is nothing new, but this is much, much more than that.</p>
<p><a href="http://s89997654.onlinehome.us/screencaps//YQL_YUI3_Twitter_example_-_jsFiddle_-_Online_Editor_for_the_Web_%28JavaScript%2C_MooTools%2C_jQuery%2C_Prototype%2C_YUI%2C_Glow_and_Dojo%2C_HTML%2C_CSS%29-20100224-215440.jpg"><img width="100%" src="http://s89997654.onlinehome.us/screencaps//YQL_YUI3_Twitter_example_-_jsFiddle_-_Online_Editor_for_the_Web_%28JavaScript%2C_MooTools%2C_jQuery%2C_Prototype%2C_YUI%2C_Glow_and_Dojo%2C_HTML%2C_CSS%29-20100224-215440.jpg"></a></p>
<p>The real power of jsFiddle is that you have the option to include any of the most popular JS libraries, including; Mootools, jQuery, Prototype, YUI2.8, YUI3, Glow, Vanilla, Dojo, Processing.js, &#038; ExtJS.  This feature gives anyone the ability to try out any of these libraries without going through the task of downloading, extracting, and coded up some examples.  With a few mouse-clicks you can view example snippets from any of the major JS libraries, and start editing them to see how they work.</p>
<p>As if that wasn&#8217;t enough, jsFiddle also includes social features that give you the ability to write a snippet, save it, and share the URL.  As I was hanging out in various JavaScript IRC chatrooms tonight, I continually found myself using jsFiddle to code up snippets to answer questions.  In the past, everyone would always just use Pastebin.com, but that lacks any interactive features.  Now you can use jsFiddle as a replacement to Pastebin for any JS, HTML, or CSS snippets and the user will have the ability to actually edit, execute, and view the output.</p>
<p>As icing on the cake, you can take your snippets, copy the embed code, and paste them anywhere.  Here&#8217;s a snippet that I was able to code up in about 15 minutes (writing this blog post took longer than that!) to demonstrate the power of YUI3, YQL, and the Twitter API.  In this iframe, you&#8217;ll find all the JS, CSS, and HTML you need to create a simple little Twitter widget.</p>
<p>In all, this is an amazing product that I&#8217;ll likely find myself using on a daily basis.</p>
<p><iframe style="width: 100%; height: 500px" src="http://jsfiddle.net/derek/Vjxt2/embedded/"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2010/jsfiddle-a-javascript-playground/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Crockford on JavaScript: Part 1</title>
		<link>http://www.derekville.net/2010/crockford-on-javascript-part-1/</link>
		<comments>http://www.derekville.net/2010/crockford-on-javascript-part-1/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 08:08:46 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Unsorted]]></category>
		<category><![CDATA[crockford]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://www.derekville.net/?p=665</guid>
		<description><![CDATA[I just finished watching Part 1 of Douglas Crockford&#8217;s ongoing lecture series on JavaScript, and it&#8217;s fascinating stuff. A must watch for any programmer. Even if you don&#8217;t code in JS, it&#8217;s worth watching simply because this first part is &#8230; <a href="http://www.derekville.net/2010/crockford-on-javascript-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<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=17880750&#038;"></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=17880750&#038;"></embed></object></div>
<p>I just finished watching Part 1 of Douglas Crockford&#8217;s ongoing lecture series on JavaScript, and it&#8217;s fascinating stuff.  A must watch for any programmer.  Even if you don&#8217;t code in JS, it&#8217;s worth watching simply because this first part is all about the history of programming. (video of talk is below)</p>
<p>As web developers, we spend anywhere from a little bit of our time to the majority of it coding in JavaScript, but few know the history behind the language.  I&#8217;m not talking about just reading the Wikipedia article and knowing that it was created by Brenden Eich at Netscape in &#8217;95, I&#8217;m talking about the history of where the ideas behind the language came from and everything that influenced it.  Like most every language, JavaScript&#8217;s syntax and style didn&#8217;t appear out of nowhere, it was influenced by a number of different languages, and those influencers were in turn also influenced by a slew of languages.  </p>
<p>It&#8217;s easy for those of us that started programming with C (or anything after) to just look at it as the &#8220;Alpha&#8221; language and ignore everything that happened before it, but that&#8217;s missing a lot of really important history, that we, as professionals, should know.  It&#8217;s like a politician in the United States just ignoring everything that happened before 1776.  Learn from the mistakes of the past and spot the trends going forward and pave the best path.  Crockford shows us snippets of languages that were created in the 60&#8242;s and 70&#8242;, dissects them, and explains why certain people thought they were good ideas at the time.  It&#8217;s amazing to think that there was a time before modules or functions, or before we had figured out the best way to format a <em>for</em> loop.  The history of programming languages is littered with a ton of bad ideas, but occasional brilliant ideas.  Those brilliant ideas are what get refined, and lay the foundation in the next generation of languages.</p>
<p>Finally, one concept he goes back to over and over that I found really interesting is that programmers are a <strong>very</strong> stubborn breed.  We all know this.  There&#8217;s little point to all our flame wars on which language or framework is better, and most of it comes from either insecurity or ignorance.  He says it takes a long time for us to evolve, and he&#8217;s right.  It&#8217;s not because new ideas aren&#8217;t coming along all the time, but it&#8217;s because the adoption of new ideas only take place at each generation shift, when  the &#8220;old&#8221; thinkers get replaced those with few preconceived notions.  The world didn&#8217;t wake up one day and realize that GOTO statements were bad, it&#8217;s that those who supported GOTO and argued for it for a decade finally retired.  Out with the old, in with the new.  That&#8217;s evolution.</p>
<p>Anyways, I could go on and on about all the &#8220;Ah hah!&#8221; moments in this talk, but you really need to watch it for yourself. I&#8217;ll probably chime in again after part 2, which I&#8217;m probably going to watch right now.  I&#8217;m excited.  It&#8217;s like a sequel.  &#8220;Ooo! What happens now?!&#8221;</p>
<p>Also, here&#8217;s the &#8220;Mother of all Demos&#8221; video he mentions about halfway through.</p>
<div align="center">
<embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=-8734787622017763097&#038;hl=en&#038;fs=true style=width:400px;height:326px allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash></embed></div>
]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2010/crockford-on-javascript-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic function names in JavaScript</title>
		<link>http://www.derekville.net/2009/dynamic-function-names-in-javascript/</link>
		<comments>http://www.derekville.net/2009/dynamic-function-names-in-javascript/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 01:48:13 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.derekville.net/?p=553</guid>
		<description><![CDATA[If you are doing some more advanced JavaScript applications, you&#8217;ll likely run into the problem at one point or another when you need to dynamically generate the name of a function you wish to call. This is the equivalent of &#8230; <a href="http://www.derekville.net/2009/dynamic-function-names-in-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are doing some more advanced JavaScript applications, you&#8217;ll likely run into the problem at one point or another when you need to dynamically generate the name of a function you wish to call. This is the equivalent of PHP&#8217;s <a href="http://php.net/manual/en/function.call-user-func.php" target="_blank">call_user_func()</a>.  </p>
<p>Here&#8217;s how you can do it.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Define some vars</span>
<span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;hello&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> bar <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;world&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> function_name <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;say_&quot;</span> <span style="color: #339933;">+</span> foo <span style="color: #339933;">+</span> bar<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Since its name is being dynamically generated, always ensure your function actually exists</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#91;</span>function_name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;function&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	window<span style="color: #009900;">&#91;</span>function_name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; World!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error.  Function &quot;</span> <span style="color: #339933;">+</span> function_name <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; does not exist.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> say_helloworld<span style="color: #009900;">&#40;</span>the_word<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: #3366CC;">&quot;Hello &quot;</span> <span style="color: #339933;">+</span> the_word<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Browser will alert &quot;Hello World!&quot;</span></pre></div></div>

<p>When you think about it, it makes a lot of sense considering all global objects in JavaScript are actually properties of the &#8220;window&#8221; object.  Take a look at this example to understand that concept a bit more.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;apple&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> foobar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;orange&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;foo&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// alerts &quot;apple&quot;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>foo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// alerts &quot;orange&quot;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;foobar&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// alerts the foobar function</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
foobar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here&#8217;s another example of when using a string to call a function could come in handy.  This time we&#8217;re calling the property of an object we&#8217;ve created.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">message</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello World!&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">say_hello</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>to<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;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> Derek <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
function_name <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;say_hello&quot;</span><span style="color: #339933;">;</span>
Derek<span style="color: #009900;">&#91;</span>function_name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>See how it looks pretty much the same as the method above using a global function?  </p>
<p>Hope that shed some light on your problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2009/dynamic-function-names-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-versioning JavaScript &amp; CSS files</title>
		<link>http://www.derekville.net/2009/auto-versioning-javascript-and-css-files/</link>
		<comments>http://www.derekville.net/2009/auto-versioning-javascript-and-css-files/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 16:45:26 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[versioning]]></category>

		<guid isPermaLink="false">http://www.derekville.net/?p=438</guid>
		<description><![CDATA[As JavaScript becomes a more integral part to the core functionality of websites, ensuring that a user has a fresh copy of the latest code is as important as ever. Normally a browser will cache certain filetypes (CSS, JS, JPG, &#8230; <a href="http://www.derekville.net/2009/auto-versioning-javascript-and-css-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As JavaScript becomes a more integral part to the core functionality of websites, ensuring that a user has a fresh copy of the latest code is as important as ever.  Normally a browser will cache certain filetypes (CSS, JS, JPG, etc&#8230;) for an indefinite period of time.  If the code within one of these cached files is updated, sometimes a browser will not know to reload that file.  So, if those changes are important for the functionality of your website, your users may run into issues and not be able to use your site properly.  Worse, they likely won&#8217;t have any idea what the issue is and will eventually give up and go elsewhere. But have no fear, there&#8217;s a solution to this problem&#8230; versioning your static files.</p>
<p>By &#8220;versioning&#8221; these files, I&#8217;m referring to changing their filenames from &#8220;my_styles.css&#8221; to &#8220;my_styles.version274.css&#8221; for example.  The problem with that example is it relies on you renaming the file and updating your includes <strong>every time</strong> you make a change.  That sounds like an nightmare, right?  Luckily there&#8217;s a neat tactic you can you to make it appear to the browser to be a new file, but it will actually be the same file and will require no effort on your part.  This variation of the versioning tactic is often referred to as &#8220;Auto-versioning&#8221;.  Here&#8217;s an example&#8230;</p>
<p>First, we use the following rewrite rule in .htaccess:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">RewriteEngine on
RewriteCond %<span style="">&#123;</span>REQUEST_FILENAME<span style="">&#125;</span> !-s # Make the file doesn't actually exist
RewriteRule ^<span style="">&#40;</span>.*<span style="">&#41;</span>\.<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>\d<span style="">&#93;</span>+\.<span style="">&#40;</span>css|js<span style="">&#41;</span>$ $1.$<span style="">2</span> <span style="">&#91;</span>L<span style="">&#93;</span></span> # Strip out the version number</pre></div></div>

<p>Now, we write the following PHP fuction:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 *  Given a file, i.e. /css/base.css, replaces it with a string containing the
 *  file's mtime, i.e. /css/base.1221534296.css.
 *  
 *  @param $file  The file to be loaded.  Must be an absolute path (i.e.
 *                starting with slash).
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> auto_version<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$mtime</span> <span style="color: #339933;">=</span> <span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'{\\.([^./]+)$}'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$mtime</span>.<span style="color: #000099; font-weight: bold;">\$</span>1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, wherever you include your CSS, change it from this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;/css/base.css&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p>To this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?=auto_version('/css/base.css')?&gt;&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p>And when rendered, will appear as:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;/css/base.1251992914.css&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p>How does this work?  Because that mod_rewrite rule above will strip out the timestamp, your server will deliver /css/base.css as the requested file.  But to the user&#8217;s browser, it will appear as a different file whenever it is updated.</p>
<p>Neat!</p>
<p></p>
<hr />
</p>
<p><strong>Note</strong>: Some strategies to fix this caching issue is to append a version # onto the end of the css or JavaScript file with a querystring, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;/css/base.css?version=1234&quot; type=&quot;text/css&quot; /&gt;</pre></div></div>

<p>This method will actually prevent the file from being cached, period!  This is bad.  You want the benefits of caching.  You don&#8217;t want to make your users pull down 100k of JavaScript &#038; CSS files on every page load.  More importantly, your servers could start to strain under the additional load.</p>
<p>Why is it not cached?  See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html">Section 13 from the HTTP Specification</a>, in particular Section 13.9</p>
<blockquote><p>
<strong>13.9 Side Effects of GET and HEAD</strong></p>
<p>Unless the origin server explicitly prohibits the caching of their responses, the application of GET and HEAD methods to any resources SHOULD NOT have side effects that would lead to erroneous behavior if these responses are taken from a cache. They MAY still have side effects, but a cache is not required to consider such side effects in its caching decisions. Caches are always expected to observe an origin server&#8217;s explicit restrictions on caching.</p>
<p>We note one exception to this rule: since some applications have traditionally used GETs and HEADs with query URLs (those containing a &#8220;?&#8221; in the rel_path part) to perform operations with significant side effects, caches MUST NOT treat responses to such URIs as fresh unless the server provides an explicit expiration time. This specifically means that responses from HTTP/1.0 servers for such URIs SHOULD NOT be taken from a cache. See section 9.1.1 for related information.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2009/auto-versioning-javascript-and-css-files/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tweenky, Zendcon, vacations, CCCKC, DotNext, etc&#8230;</title>
		<link>http://www.derekville.net/2008/tweenky-zendcon-vacations-ccckc-dotnext-etc/</link>
		<comments>http://www.derekville.net/2008/tweenky-zendcon-vacations-ccckc-dotnext-etc/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 04:51:55 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ccckc]]></category>
		<category><![CDATA[dotnext]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[openweb podcast]]></category>
		<category><![CDATA[tweenky]]></category>
		<category><![CDATA[zendcon]]></category>

		<guid isPermaLink="false">http://www.derekville.net/2008/09/26/tweenky-zendcon-vacations-ccckc-dotnext-etc/</guid>
		<description><![CDATA[Blogging is something that comes in waves for me, and once I get out of the habit, it is tough to get back into it.  I enjoy it, but sometimes there’s just so much going on that it completely escapes &#8230; <a href="http://www.derekville.net/2008/tweenky-zendcon-vacations-ccckc-dotnext-etc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Blogging is something that comes in waves for me, and once I get out of the habit, it is tough to get back into it.  I enjoy it, but sometimes there’s just so much going on that it completely escapes me.  The last few months have been one of those periods.  So let’s start from the top…</p>
<p>I’ve been working on a new project recently.  <a href="http://www.tweenky.com">Tweenky</a> is a micro blogging client I am developing that is mostly used with Twitter, but also supports Identi.ca, and hopefully more micro-blogging services soon.  The concept behind it was the lack of any good web clients out there for Twitter, and especially ones that brought back the “track” feature that Twitter took away from us a few weeks back.  It’s still very much a work in progress and I just have to find the time to work on some of the new features and further improve stability.  I’m having a blast with pushing the boundaries of JavaScript and what it should/shouldn’t be used for.  So, if you are a Twitter user, go check it out, and if it is still requiring an invite code, use “derekville”.</p>
<p>So I just returned from a convention out in Santa Clara called Zendcon.  As a web developer, my primary language of choice is PHP, and Zend is the company puts most of the work into the PHP project, so this was kind of their little yearly shindig.  It was 4 days of 1-2 hour training sessions on all topics related to PHP and web development.  I saw some presentations from engineers and developers from companies such as IBM, Google, Mozilla, Digg, Yahoo, and tons more.  I met a ton of really interesting people too and had a great time at Yahoo HQ for Hackday &#8217;08.  (note to self: Don&#8217;t wear &#8220;Hackday &#8217;08&#8243; shirt to airport, it leads to hacker questioning from TSA agents)</p>
<p>Vacation #1 was on the front &amp; back end of the Zendcon trip as I had a few days before &amp; after the conference to play around in San Francisco.  It’s such a cool city and I had a blast driving around in the Pontiac G6 convertible I rented for the week.  I’ve never had so much fun driving a car!</p>
<p>Vacation #2 is coming up next month with Katye &amp; I flying up to Seattle where we’ll also head up to Vancouver &amp; Victoria.  I haven’t been to Seattle in about 10 years, so I’m really excited as I love that city.  Everyone I’ve talked to raves about Vancouver too, so I’m pretty excited about my first trip north of the border.</p>
<p>If you are a web developer in the Kansas City area, you need to check out two emerging groups.  The first being <a href="http://webstandards.meetup.com/121/">DotNext</a>, a group in the KC area that gets together every month or so to give sessions on anything web development related.  Last month was a series of presentations of Amazon Web Services.  This month is going to be on various database related technologies. The second group is <a href="http://cowtowncomputercongress.org/index.php/Main_Page">Cowtown Computer Congress</a> who is setting up a hacker space in North Kansas City.  For those not too familiar with what a “hacker space” is (myself included), it is a place for technologists to get together to work on  various hardware &amp; software projects, share costs on equipment, and actually socialize (something most geeks never do much of).  So should be an awesome place to convene when it officially opens in the next couple months.</p>
<p>And finally, a new podcast from some rather influential people in the web development world has launched that I’d like to mention.  <a href="http://openwebpodcast.com/">Open Web Podcast</a> was created by Google engineer <a href="http://almaer.com/blog/">Dion Almaer</a> (of the Ajaxian podcast as well), <a href="http://alex.dojotoolkit.org/">Alex Russell</a> of Dojo, and <a href="http://ejohn.org/">John Resig</a> of Mozilla/jQuery.  So if you are into web standards and JavaScript, definitely check it out.</p>
<p>Finally, I recently discovered the FX show &#8220;It&#8217;s Always Sunny in Philadelphia&#8221;.  Hilarious!  Check out all the episodes on <a href="http://www.hulu.com/its-always-sunny-in-philadelphia">Hulu</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2008/tweenky-zendcon-vacations-ccckc-dotnext-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First AJAX script</title>
		<link>http://www.derekville.net/2005/first-ajax-script/</link>
		<comments>http://www.derekville.net/2005/first-ajax-script/#comments</comments>
		<pubDate>Sat, 28 May 2005 23:03:06 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.derekville.net/?p=13</guid>
		<description><![CDATA[Well, I finally got around to giving Ajax (Asynchronous JavaScript and XML) a whirl. I wasn&#8217;t trying to do anything spectacular, just something functional to wet my appetite. I started out just wanting to allow people to send me text &#8230; <a href="http://www.derekville.net/2005/first-ajax-script/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Well, I finally got around to giving <a href="http://en.wikipedia.org/wiki/AJAX">Ajax</a> (Asynchronous JavaScript and XML) a whirl.  I wasn&#8217;t trying to do anything spectacular, just something functional to wet my appetite.  I started out just wanting to allow people to send me text messages via the side bar.  I got it all set up using PHP in about 2 minutes, and I thought&#8230; &#8220;It works, but I hate reloading the page for something so simple.&#8221;  And then Ajax popped in my head and thought it would be a great first script.</p>
<p>So off I went to grab the latest version of <a href="http://www.modernmethod.com/sajax/">SAJAX</a> (Simple Ajax), and boy were they right about the &#8220;simple&#8221; part.  Within about 30 minutes, I had a functional script that you can now find on the side bar.  Before you try it out, please use the <a href="http://www.derekgathright.com/ajax_send_mail.php">demo page</a>, as I don&#8217;t need everyone sending me text messages just to see how it works.</p>
<p>Next step, getting my responses to show up. =)</p>
<p>Edit:  At first that last comment was a joke, <a href="http://www.derekgathright.com/chat_full.php">but two hours later&#8230;</a>, that was shockingly easy.  I&#8217;d like to get it integrated into the side bar, but out of time tonight.  I&#8217;ll post the code when I have a bit more time to work on it.  So feel free to send a message or two, as I can respond rather easily.  If you get annoying, I can turn it off via my cell phone too.  <img src='http://www.derekville.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.derekville.net/2005/first-ajax-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
