<?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>arkinEx Codex &#187; Javascript</title>
	<atom:link href="http://www.arkinex.com/contains/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arkinex.com</link>
	<description>the place where all my code can be viewed</description>
	<lastBuildDate>Wed, 04 Nov 2009 20:39:07 +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>Automatically Version your Javascript &amp; Stylesheets</title>
		<link>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/</link>
		<comments>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 17:34:06 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=36</guid>
		<description><![CDATA[Recently, I was browsing the internet, as you do, and I came across a great little article that discussed the automatic versioning of stylesheets, javascript, flash and image files. As i constantly have to hold shift when refreshing to get a full page refresh, I decided this method was genius and decided there were a [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was browsing the internet, as you do, and I came across a great little article that discussed the automatic versioning of stylesheets, javascript, flash and image files.</p>
<p>As i constantly have to hold shift when refreshing to get a full page refresh, I decided this method was genius and decided there were a few things needed to make it perfect.<br />
<span id="more-36"></span><br />
First of all, I couldn&#8217;t get the cache code which goes in .htaccess to work, after closer inspection you must make sure mod_expires is enabled on your server (if you run your own), otherwise you will see a 500 error.</p>
<p>Secondly, the autoVer ended up breaking my javascript and stylesheet files as I name them with multiple periods and it was subsequently replacing them all with numbers so i ended up with filenames like <em>framework.1230203232.version.21302302.two.js</em> which is a bit over the top.</p>
<p>Anyway, this is my revised version, for those of you who haven&#8217;t read <a href="http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/">Particletree</a>, you don&#8217;t necessarily need to, I will cover all the required parts.</p>
<p>First of all, we modify <em>.htaccess</em> so that it sets an expiry date on all stylesheets, images and javascript files.</p>
<p><em>.htaccess</em></p>
<pre class="Style">&lt;FilesMatch "\.(gif|png|jpg|js|css|swf)$"&gt;
    ExpiresActive On
    ExpiresDefault "access plus 10 years"
&lt;/FilesMatch&gt;
#Rules for the versioned files
RewriteRule ^(scripts|css|images)/(.+)\.([a-zA-Z0-9]+)\.(js|css|jpg|gif|png)$ $1/$2.$4 [L]</pre>
<p>This will make all images, stylesheets, flash and javascript cache for 10 years (reduces load on your server and bandwidth costs) and also adds the <em>RewriteRule</em> which handles the version file pointing to the normal files.</p>
<p>Next, we want to add the function, ideally you want this defined on every page, so stick it somewhere good.</p>
<p><em>the Auto Version function</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> autoVer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</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: #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;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$f</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</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;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</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;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the case that php cannot find the file, it still might exist, so the function just returns the parameters it was given.</p>
<p>Next, we rewrite the <em>HEAD</em> part of your html, this file must be <em>PHP</em> for it to work, and the function must be included (either at the top of the page or within another file).</p>
<p><em>My HEAD area</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>head<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>title<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>arkinEx<span style="color: #339933;">.</span>com <span style="color: #339933;">-</span> Autoversion Your Javascript <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> CSS Stylesheets<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>title<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content-type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>meta name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;author&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;arkinEx&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/stylesheets/design.css')?&amp;gt;&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/javascript/mootools-core.js')?&amp;gt;&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/javascript/mootools-more.js')?&amp;gt;&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/javascript/mootools-pastejax.js')?&amp;gt;&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>head<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Which, then, will produce a nice output something like this:<br />
&lt;pre lang=&#8221;html&#8221;&gt;<br />
&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;/resources/stylesheets/design.aHegDd.css&#8221; /&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/resources/javascript/mootools-core.a45S.js&#8221;&gt;&lt;/script&gt;</p>
<p>You get the idea, so try it out, let me know how you found it.</p>
<p>The Original Article: &#8220;<a href="http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/">Automatically Version Your CSS and Javascript Files</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Javascript Framework</title>
		<link>http://www.arkinex.com/javascript/frameworks/11/jquery-121/</link>
		<comments>http://www.arkinex.com/javascript/frameworks/11/jquery-121/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 22:08:53 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/javascript/frameworks/11/jquery-121/</guid>
		<description><![CDATA[Recently I tried to take my knowledge of Javascript to a new level, because, on the whole, it was pretty dire. Whilst looking into new techniques and reading tutorials I came across some useful Javascript frameworks, specifically, jQuery, which caught my attention immediately. Why did i pick jQuery? jQuery is a fast, concise, JavaScript Library [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/resources/images/jquery-icon.png" alt="jQuery icon" align="right" border="0" height="18" hspace="10" vspace="7" width="80" />Recently I tried to take my knowledge of Javascript to a new level, because, on the whole, it was pretty dire.</p>
<p>Whilst looking into new techniques and reading tutorials I came across some useful Javascript frameworks, specifically, <strong>jQuery</strong>, which caught my attention immediately.</p>
<p><span id="more-11"></span></p>
<h2>Why did i pick jQuery?</h2>
<blockquote><p>jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. <strong>jQuery is designed to change the way that you write JavaScript.</strong></p></blockquote>
<p>There are a few reasons why jQuery caught my eye:</p>
<ul>
<li>Easy to understand and pick up/learn.</li>
<li>Minimalistic in size and functions.</li>
<li>Great documentation (and examples).</li>
<li>Plugins archive to die for.</li>
</ul>
<h3>Easy to understand and pick up/learn.</h3>
<p>When comparing jQuery to the other frameworks (such as prototype/scriptaculous/ext). I found jQuery very easy to understand, it has great documentation on every function and the function names relate to what they are actually doing.</p>
<p>An Example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.surprise&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ohmy&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This would change the paragraph html element with class=suprise to class=&#8221;surpise ohmy&#8221;.</p>
<p>If there were any height, width, opacity differences, it would alter them slowly.</p>
<p>Not only are the functions incredibly easy to understand and learn, but they implement well together.</p>
<h3>Minimalistic in size and functions.</h3>
<p>When you download jQuery (1.2.1), you have 3 download options:</p>
<ul>
<li><a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.1.min.js">jQuery for production use</a> @ 14Kb (Minified and gzipped)</li>
<li><a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.1.js">jQuery for development and testing</a> @ 77Kb (Uncompressed)</li>
<li><a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.1.pack.js">jQuery for non-gzip users</a> @ 26Kb (Packed)</li>
</ul>
<p>For the first option, it would take a standard user less than a second to load the jQuery library when visiting your site, even if they were 56K it would only take around 2.8 seconds, which is not bad considering it takes alot longer to load the average image.</p>
<h3>Great documentation (and examples)</h3>
<p>When i first starting learning and trying to understand jQuery, the functions and methods of using them were not sticking in my head, so I frequently had the <a href="http://docs.jquery.com/">jQuery API Documentation</a> open which has great tutorials, examples and demonstrations to help you understand where you are going wrong and how certain features are supposed to operate.</p>
<h3>Plugins archive to die for</h3>
<p>At my last count, the <a href="http://jquery.com/plugins/">jQuery Plugins directory</a> had just over 500 plugins in 20 categories. Not only that, but each one of the plugins comes unpacked meaning you can edit the code to suit your needs.</p>
<p>This was the best feature i probably found because i could see how other users had implemented jQuery to their own requirements and i could also take a look at their code to understand the jQuery framework further.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/javascript/frameworks/11/jquery-121/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
