<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>JavaScript Rules</title> <link>http://www.javascriptrules.com</link> <description /> <lastBuildDate>Thu, 26 Aug 2010 04:56:39 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JavaScriptRules" /><feedburner:info uri="javascriptrules" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Web Metrics Framework</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/7oX0mnAHmTM/</link> <comments>http://www.javascriptrules.com/2010/08/25/web-metrics-framework/#comments</comments> <pubDate>Thu, 26 Aug 2010 04:56:39 +0000</pubDate> <dc:creator>Marcel Duran</dc:creator> <category><![CDATA[performance]]></category> <category><![CDATA[google]]></category> <category><![CDATA[metrics]]></category> <category><![CDATA[yslow]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=401</guid> <description><![CDATA[Recently Google Web Metrics report came across and inspired by my co-worker Stoyan Stefanov&#8217;s WTF &#8211; Web Testing Framework I decided to build my own ruleset for YSlow using these metrics to check how good or bad pages are compared to Top and All Sites averages. Last edition of O&#8217;Reilly Velocity Conference, Stoyan demonstrated how easy [...]]]></description> <content:encoded><![CDATA[<p>Recently <a href="http://code.google.com/speed/articles/web-metrics.html" target="_blank">Google Web Metrics</a> report came across and inspired by my co-worker Stoyan Stefanov&#8217;s <a href="http://www.phpied.com/wtf/" target="_blank">WTF &#8211; Web Testing Framework</a> I decided to build my own ruleset for <a href="http://developer.yahoo.com/yslow/" target="_blank">YSlow</a> using these metrics to check how good or bad pages are compared to Top and All Sites averages.</p><p><span id="more-401"></span>Last edition of <a href="http://en.oreilly.com/velocity2010" target="_blank">O&#8217;Reilly Velocity Conference</a>, Stoyan demonstrated <a href="http://en.oreilly.com/velocity2010/public/schedule/detail/15306" target="_blank">how easy is to build your own YSlow ruleset</a> and following his <a href="http://www.phpied.com/wtf/" target="_blank">post</a> and <a href="http://github.com/stoyan/Web-Testing-Framework/" target="_blank">source code</a> I was able to make it.<br /> This first release of this <a href="http://labs.javascriptrules.com/wmf/" target="_blank">extension</a> of <a href="http://developer.yahoo.com/yslow/" target="_blank">extension</a> of <a href="http://getfirebug.com/" target="_blank">extension</a> features:</p><ul><li>Google Web Metrics from 2010-05-26</li><li>Top and All Sites metrics rulesets</li><li>Use percentile to score when available</li><li>Use SSH metrics for HTTPS pages</li></ul><p><img src="http://cdn-javascriptrules.2static.it/i/posts/wmf.png" alt="Screenshot: Web Metrics Framework for YSlow for Firebug for Firefox" /></p><h3>Gimme!</h3><ul><li>The code is <a href="http://github.com/marcelduran/Web-Metrics-Framework" target="_blank">in GitHub</a></li><li>Install it from <a href="https://addons.mozilla.org/en-US/firefox/addon/221495/">Mozilla Addon Page</a> or <a href="http://labs.javascriptrules.com/wmf/download/">Download Page</a></li></ul><h3>Usage</h3><p>After installing this extension you will see 2 new rulesets in the YSlow rulesets drop down list:</p><ol><li>Web Metrics Framework &#8211; Top Sites</li><li>Web Metrics Framework &#8211; All Sites</li></ol><p>Choose one of these rulesets and click <strong>Run Test</strong> button. The current page will be evaluated using the Google web metrics data.</p><h3>Metrics</h3><p>The metrics provided by Google on its article are mainly averages with some percentiles and SSL data. YSlow rules need a lint function that evaluates an input returning a score from 0 to 100 which is later used to give the F to A score system using weights.<br /> Since not all metrics have percentiles I had to compare the page metrics with the average multiplied by a magic number (4) to create a range from 0 to 4*average (if any statistic savvy here has comments on it please help me out to find a better way to evaluate) which is good enough to have an outcome where being in the average deserves a C. Perhaps Google releases new reports in future updates with all metrics percentiles, this extension could benefit from those numbers and become more accurate.<br /> If the page being checked is secure (HTTPS), the SSL data available on the report is used instead.<br /> The weighting distribution was given by:</p><ol><li>Every metric starts with 1</li><li>Metrics with percentile get 1 more</li><li>Metrics directly related to wire traffic payload or number of requests also get 1 more</li></ol><p><em>* Again: statistics savvy, help me improving this extension with your valuable feedback</em></p><h3>Conclusion</h3><p>Although these metrics aren&#8217;t 100% accurate (see <a href="http://code.google.com/speed/articles/web-metrics.html" target="_blank"> <strong>Caveats section</strong></a> on Google&#8217;s article) it&#8217;s a good resource to compare your site with a sample of several billion pages crawled by Googlebot. Have fun!</p><p>WARNING: Like <a href="http://jslint.com/" target="_blank">JSLint</a>, Web Metrics Framework might hurt your feelings :-)</p><p>DISCLAIMER: This extension is not related with Google Inc. or Yahoo! Inc.</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/7oX0mnAHmTM" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2010/08/25/web-metrics-framework/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2010/08/25/web-metrics-framework/</feedburner:origLink></item> <item><title>New posts about performance. Back and alive!</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/aB8qVMhn61k/</link> <comments>http://www.javascriptrules.com/2010/04/27/new-posts-about-performance-back-and-alive/#comments</comments> <pubDate>Wed, 28 Apr 2010 02:33:57 +0000</pubDate> <dc:creator>Marcel Duran</dc:creator> <category><![CDATA[Yahoo!]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[ydn]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=384</guid> <description><![CDATA[After a long period of no posts due to personal issues, I&#8217;m back now and alive! This time with a new post on YDN &#8211; Yahoo! Developer Network &#8211; blog: Performance on Yahoo! Search for Earth Day. In this post I describe the performance case study of Yahoo! Search Earth Day campaign. During this long off-post period, besides [...]]]></description> <content:encoded><![CDATA[<p>After a long period of no posts due to personal issues, I&#8217;m back now and alive!<br /> This time with a new post on <a href="http://developer.yahoo.net/blog/">YDN</a> &#8211; Yahoo! Developer Network &#8211; blog: <a href="http://developer.yahoo.net/blog/archives/2010/04/performance_on_yahoo_search_earth_day_data_uri_ftw.html">Performance on Yahoo! Search for Earth Day</a>.<br /> In this post I describe the performance case study of <a href="http://search.yahoo.com/">Yahoo! Search</a> <a href="http://events.yahoo.com/earthday/2010/">Earth Day campaign</a>.</p><p>During this long off-post period, besides my day job, I&#8217;ve been doing some experiments, developing some tools and brainstorming lots of ideas, mostly related to performance and JavaScript. I do have some post drafts and will be publishing them soon. Here are a few topics I&#8217;m covering along this year:</p><ul><li>setTimeout minimum delay limit</li><li>Prefetching CSS images</li><li>Problems with gradients filters on IE links hover</li><li>Flipping page direction RTL/LTR easily – <a href="https://addons.mozilla.org/en-US/firefox/addon/114416">RTLzr</a> a Firefox extension</li><li>JavaScript Interviews Exposed (series)</li><li>Lazy Enhancement</li><li>JavaScript video subtitle</li><li>JavaScript video timeline marks</li><li>Deleting a removed node from DOM</li></ul><p>Stay tuned!</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/aB8qVMhn61k" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2010/04/27/new-posts-about-performance-back-and-alive/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2010/04/27/new-posts-about-performance-back-and-alive/</feedburner:origLink></item> <item><title>Finding prime numbers with Javascript</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/3WO40bv7NC8/</link> <comments>http://www.javascriptrules.com/2009/10/16/finding-prime-numbers-with-javascript/#comments</comments> <pubDate>Fri, 16 Oct 2009 17:45:05 +0000</pubDate> <dc:creator>Rafael Coelho</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[algorithm]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[eratosthenes]]></category> <category><![CDATA[JVM]]></category> <category><![CDATA[opera]]></category> <category><![CDATA[primalty]]></category> <category><![CDATA[prime]]></category> <category><![CDATA[rhino]]></category> <category><![CDATA[sieve]]></category> <category><![CDATA[SPOJ]]></category> <category><![CDATA[v8]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=261</guid> <description><![CDATA[A few days ago I introduced a friend of mine Jorge Rocha to SPOJ an online judge system for user-submitted programs, one of the first problems that he tried was the Prime Generator it consisted in finding all primes in a given range of numbers, after some time and few different algorithms he asked me [...]]]></description> <content:encoded><![CDATA[<p>A few days ago I introduced a friend of mine Jorge Rocha to <a href="https://www.spoj.pl/">SPOJ</a> an online judge system for user-submitted programs, one of the first problems that he tried was the <a href="https://www.spoj.pl/problems/PRIME1/">Prime Generator</a> it consisted in finding all primes in a given range of numbers, after some time and few different algorithms he asked me if I had any tips to help him, although he had the correct algorithm <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">(Sieve of Eratosthenes)</a> something was clearly missing, the solution wasn&#8217;t fast enough and I had no clue where to go from there, so as usual when a question like that comes up I resort to <a href="http://fzort.org/mpr/">Mauro Persano</a>&#8230; and obviously he knew the answer, he taught us how to apply a heuristic to the algorithm to help solve the problem and after doing so the code worked and the solution was approved.</p><p><span id="more-261"></span>Although I&#8217;m not really into crazy algorithms challenges I thought I&#8217;d give it a try just to see how fast the solution would be in JS, note that most of the solutions submitted are in C/C++ or Java, much faster than JS and to make things worst the interpreter was <a href="http://www.mozilla.org/rhino/">Rhino</a>, anyways we went ahead and recreated the solution in Javascript, so now it was time to test it&#8230; a little more tweaking to make it receive inputs via console and we had it running, right away we realized that our output via <a href="http://en.wikipedia.org/wiki/Standard_streams#Standard_output_.28stdout.29">stdout</a> was slowing us down, printing 10 times in a row all primes until 1 billion in the shell is not really fast but it was required to, I knew we had little or no chances to get approved but anyways we tried&#8230; and as I suspected we didn&#8217;t get approved :(, but I decided to test locally in different browsers/engines with and without output.</p><p>Here are the results, I also built a <a href="http://sandbox.javascriptrules.com/prime1/" target="_blank">test runner</a> so you can test on your own:</p><ul><li>Chrome is usually the best, <a href="http://code.google.com/p/v8/">V8</a> is blazing fast but it chokes when outputting the results through <a href="http://webkit.org/">WebKit</a></li><li>Rhino does a great job specially with a high number of runs because of <a href="http://en.wikipedia.org/wiki/Java_Virtual_Machine">JVM</a></li><li>Firefox runs nicely with short ranges but stops the script because of the <a href="http://www.nczonline.net/blog/2009/01/05/what-determines-that-a-script-is-long-running/">long time running</a></li><li>Opera wasn&#8217;t fast but it never crashed or stopped</li></ul><p><br/></p><table border="0" align="center" width="100%"><tr><th rowspan="2">Browser/Engine</th><th rowspan="2"># of runs</th><th colspan="2">Avg Time (ms)</th></tr><tr><th>Range: 0 &#8211; 100 thousand</th><th>Range: 0 &#8211; 1 million</th></tr><tr><td>Rhino 1.7 *</td><td align="center">10</td><td align="right">250</td><td align="right">2330</td></tr><tr><td>Firefox 3.5.3 *</td><td align="center">10</td><td align="right">670</td><td align="right">Stopped</td></tr><tr><td>Chrome 4.0 *</td><td align="center">10</td><td align="right">32</td><td align="right">3050</td></tr><tr><td>Opera 10 *</td><td align="center">10</td><td align="right">540</td><td align="right">4956</td></tr><tr><td>Rhino 1.7</td><td align="center">100</td><td align="right">34</td><td align="right">304</td></tr><tr><td>Firefox 3.5.3</td><td align="center">100</td><td align="right">20</td><td align="right">Stopped</td></tr><tr><td>Chrome 4.0</td><td align="center">100</td><td align="right">9</td><td align="right">128</td></tr><tr><td>Opera 10</td><td align="center">100</td><td align="right">100</td><td align="right">1213</td></tr><tr><td colspan="4">* With output (tested under <a href="http://www.ubuntu.com/">Ubuntu 9.04 Jaunty</a>)</td></tr></table> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/3WO40bv7NC8" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/10/16/finding-prime-numbers-with-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/10/16/finding-prime-numbers-with-javascript/</feedburner:origLink></item> <item><title>JavaScript Challenge Revisited: Lotto Number Generator in Chains</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/Kfj6L0fZ08g/</link> <comments>http://www.javascriptrules.com/2009/10/06/javascript-challenge-revisited-lotto-number-generator-in-chains/#comments</comments> <pubDate>Tue, 06 Oct 2009 17:16:15 +0000</pubDate> <dc:creator>Marcel Duran</dc:creator> <category><![CDATA[challenge]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[chaining]]></category> <category><![CDATA[ecma]]></category> <category><![CDATA[minification]]></category> <category><![CDATA[problem]]></category> <category><![CDATA[random]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=270</guid> <description><![CDATA[Matthias Reuter from United Coders proposed a JavaScript Challenge: A Lotto Number Generator which the rules follow: Write a JavaScript function that generates random lotto numbers. This function has to return an array of six different numbers from 1 to 49 (including both) in ascending order. You may use features of ECMA-262 only, that means no [...]]]></description> <content:encoded><![CDATA[<p>Matthias Reuter from <a href="http://www.united-coders.com/" target="_blank">United Coders</a> proposed a <a href="http://www.united-coders.com/matthias-reuter/javascript-challenge-lotto-number-generator" target="_blank">JavaScript Challenge: A Lotto Number Generator</a> which the rules follow:</p><blockquote><p>Write a JavaScript function that generates random lotto numbers. This function has to return an array of six different numbers from 1 to 49 (including both) in ascending order. You may use features of <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" target="_blank">ECMA-262</a> only, that means no Array.contains and stuff. You must not induce global variables.</p><p>The function has to look like this</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> getRandomLottoNumbers <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// your implementation here</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div><p>Minify your function using <a href="http://javascript.crockford.com/jsmin.html" target="_blank">JSMin</a> (level aggressive) and count the bytes between the outer curly braces.</p></blockquote><p><span id="more-270"></span>It might look simple but it turns out to be an interesting challenge considering there&#8217;s a bunch of ways to solve it where the length of the minified final implementation is the main concern: the smaller the better. He describes his solution and invites others to post their solutions as comments. His final solution for such challenge has 86 bytes:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> n<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>for<span style="color: #009900;">&#40;</span><span style="color: #339933;">;++</span>i<span style="color: #339933;">&lt;</span><span style="color: #CC0000;">50</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>n.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>for<span style="color: #009900;">&#40;</span><span style="color: #339933;">;--</span>i<span style="color: #339933;">&gt;</span><span style="color: #CC0000;">6</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>n.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">|</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>return n</pre></div></div><p>Some readers wrote even smaller solutions such as:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,,,,,,</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">50</span><span style="color: #339933;">|</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span></pre></div></div><p>However this one is by far the smallest, 49 bytes only, it is invalid because it doesn&#8217;t fulfill the rules for the following reasons:</p><ol><li><code>map</code> is not part of ECMA-262 specification</li><li><code>[,,,,,,]</code> is inconsistent across browsers, IE would create an array of 7 <code>undefined</code> values</li><li>it&#8217;s not in ascending order</li><li>may contain duplicated values</li></ol><p>So far the smallest solution that fulfills all the rules has 65 bytes:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> v<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>m<span style="color: #339933;">=</span><span style="color: #CC0000;">6</span><span style="color: #339933;">,</span>n<span style="color: #339933;">=</span><span style="color: #CC0000;">49</span><span style="color: #339933;">;</span>m<span style="color: #339933;">;--</span>n<span style="color: #009900;">&#41;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>n<span style="color: #339933;">&gt;</span>m<span style="color: #339933;">?</span><span style="color: #CC0000;">0</span><span style="color: #339933;">:</span>v<span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>m<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>n<span style="color: #339933;">;</span>return v</pre></div></div><h3>Revisiting</h3><p>I&#8217;ve also contributed with my solution but with another fashion way: Using a single line chaining solution, i.e. no semi-colons separating statements, like: <code>return a().b.c().d.e()</code></p><p>My solution has 200 bytes:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/0/g</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>Array.<span style="color: #660066;">a</span><span style="color: #339933;">=</span>Array.<span style="color: #660066;">a</span><span style="color: #339933;">||</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>var x<span style="color: #339933;">;</span>while<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">=</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">50</span><span style="color: #339933;">|</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #000066; font-weight: bold;">in</span> Array.<span style="color: #660066;">a</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>Array.<span style="color: #660066;">a</span><span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>return x<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">delete</span> Array.<span style="color: #660066;">a</span><span style="color: #339933;">;</span>return a<span style="color: #339933;">-</span>b<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div><p>It&#8217;s not the smallest compared to the other solutions but it does fulfill the rules and is in a single line chaining. It might be a little obscure for some but I will break it down into smaller peaces:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">return</span>
    <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>   <span style="color: #006600; font-style: italic;">// creates an array with 6 positions filled with 0's</span>
    .<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>         <span style="color: #006600; font-style: italic;">// converts the array into string: &quot;0,0,0,0,0,0&quot;</span>
    .<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/0/g</span><span style="color: #339933;">,</span>  <span style="color: #006600; font-style: italic;">// replaces all 0's in the string using the following function</span>
        <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Array.<span style="color: #660066;">a</span> <span style="color: #339933;">=</span> Array.<span style="color: #660066;">a</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>        <span style="color: #006600; font-style: italic;">// augments Array with an object property only once</span>
            <span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">;</span>                          <span style="color: #006600; font-style: italic;">// variable to store a random number</span>
            <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>                         <span style="color: #006600; font-style: italic;">// while condition: assures no dupes</span>
                <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">=</span>                        <span style="color: #006600; font-style: italic;">// assigning a value to x:</span>
                    Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">50</span> <span style="color: #339933;">|</span> <span style="color: #CC0000;">1</span>  <span style="color: #006600; font-style: italic;">// generates a random number times 50 or 1 (when 0)</span>
                <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">in</span> Array.<span style="color: #660066;">a</span>                <span style="color: #006600; font-style: italic;">// checks if x isn't in the augmented Array object</span>
            <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>                            <span style="color: #006600; font-style: italic;">// empty block for while statement</span>
            Array.<span style="color: #660066;">a</span><span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>                 <span style="color: #006600; font-style: italic;">// adds number as property into Array object</span>
            <span style="color: #000066; font-weight: bold;">return</span> x                        <span style="color: #006600; font-style: italic;">// replaces the &quot;0&quot; found by the random x number</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span>               <span style="color: #006600; font-style: italic;">// end of replace function</span>
    .<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span>     <span style="color: #006600; font-style: italic;">// converts string into array of strings using comma as separator</span>
    .<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span>          <span style="color: #006600; font-style: italic;">// sorts the array using the following compare function</span>
        <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   <span style="color: #006600; font-style: italic;">// elements to be compared</span>
            <span style="color: #000066; font-weight: bold;">delete</span> Array.<span style="color: #660066;">a</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// restores Array, removing previously augmented property</span>
            <span style="color: #000066; font-weight: bold;">return</span> a <span style="color: #339933;">-</span> b    <span style="color: #006600; font-style: italic;">// &lt; 0 then a &lt; b; = 0 then a = b; &gt; 0 a &gt; b</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span>               <span style="color: #006600; font-style: italic;">// end of sort, a sorted array is returned</span></pre></div></div><p>I also invite you to post your single line chaining solution as a comment. Happy chaining. ;-)</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/Kfj6L0fZ08g" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/10/06/javascript-challenge-revisited-lotto-number-generator-in-chains/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/10/06/javascript-challenge-revisited-lotto-number-generator-in-chains/</feedburner:origLink></item> <item><title>YUI 3 first release is out</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/pXh9HHWHD60/</link> <comments>http://www.javascriptrules.com/2009/09/29/yui-3-first-release-is-out/#comments</comments> <pubDate>Wed, 30 Sep 2009 01:28:13 +0000</pubDate> <dc:creator>Rafael Coelho</dc:creator> <category><![CDATA[YUI]]></category> <category><![CDATA[Yahoo!]]></category> <category><![CDATA[YUI3]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=251</guid> <description><![CDATA[I&#8217;m more than pleased to announce that the 3rd generation of YUI is finally out, I&#8217;ve been following closely the YUI project ever since I joined Yahoo! almost 4 years ago and since then the framework has evolved incredibly, the 3rd version announced today is a complete redesign, the framework became faster, lighter and easier [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;m more than pleased to announce that the 3rd generation of <a href="http://developer.yahoo.com/yui/3/" target="_blank">YUI</a> is finally out, I&#8217;ve been following closely the YUI project ever since I joined Yahoo! almost 4 years ago and since then the framework has evolved incredibly, the 3rd version announced today is a complete redesign, the framework became faster, lighter and easier to use, quoting <a href="http://www.yuiblog.com/blog/2009/09/29/yui-3-0-0/">Eric Miraglia: </a> <em>&#8220;One of the goals of the YUI 3 redesign was to make it easy to use without sacrificing power, performance and configurability.&#8221;</em></p><p>Go ahead and give it a try, the YUI Blog post is a good starting point <a href="http://www.yuiblog.com/blog/2009/09/29/yui-3-0-0/">YUI 3.0.0: First GA Release of YUI’s Next-Generation Codeline</a></p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/pXh9HHWHD60" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/09/29/yui-3-first-release-is-out/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/09/29/yui-3-first-release-is-out/</feedburner:origLink></item> <item><title>Harnessing the juice out of Yahoo! Pipes</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/EsQHWI9XUAw/</link> <comments>http://www.javascriptrules.com/2009/09/27/harnessing-the-juice-out-of-yahoo-pipes/#comments</comments> <pubDate>Sun, 27 Sep 2009 14:49:41 +0000</pubDate> <dc:creator>Rafael Coelho</dc:creator> <category><![CDATA[Yahoo!]]></category> <category><![CDATA[Pipes]]></category> <category><![CDATA[WebService]]></category> <category><![CDATA[WS]]></category> <category><![CDATA[YQL]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=237</guid> <description><![CDATA[While working on my current project at Yahoo! I had the need to aggregate different search feeds, the requirement was to have a way to pass a param to the url like search=search_term, and this would be passed along to the the feeds and it would return results from all the feeds (obviously it had [...]]]></description> <content:encoded><![CDATA[<p>While working on my current project at Yahoo! I had the need to aggregate different search feeds, the requirement was to have a way to pass a param to the url like <em>search=search_term</em>, and this would be passed along to the the feeds and it would return results from all the feeds (obviously it had to be done in the front end only), I thought about adding more <a href="http://developer.yahoo.com/yql/console" target="_blank">YQL</a> requests to my app but I didn&#8217;t want to change the code since we were planning on having a re-factor of this part of the code, so super <a href="http://pipes.yahoo.com" target="_self">Yahoo! Pipes</a> to the rescue, it was a really easy task and got more than I asked for, like filters and sorting&#8230; the example speaks for itself: <a href="http://pipes.yahoo.com/pipes/pipe.info?_id=4c40a274bec11e41ab22e5c91e5df9f2" target="_self">pipe example</a> you can clone it and play with it.</p><p>You can also check all the other cool examples created by Paul Donnelly <a href="http://pipes.yahoo.com/31337" target="_self">http://pipes.yahoo.com/31337</a> or even check <a href="http://blog.pipes.yahoo.net/">Pipes Blog</a> for their latest updates.</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/EsQHWI9XUAw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/09/27/harnessing-the-juice-out-of-yahoo-pipes/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/09/27/harnessing-the-juice-out-of-yahoo-pipes/</feedburner:origLink></item> <item><title>Fast min/max in arrays</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/N5tcfxuf93Q/</link> <comments>http://www.javascriptrules.com/2009/09/23/fast-minmax-in-arrays/#comments</comments> <pubDate>Wed, 23 Sep 2009 21:03:36 +0000</pubDate> <dc:creator>Marcel Duran</dc:creator> <category><![CDATA[algorithm]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[Array]]></category> <category><![CDATA[Math]]></category> <category><![CDATA[max]]></category> <category><![CDATA[min]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=213</guid> <description><![CDATA[This morning while commuting to the office, reading JavaScript for Web Developers, I bumped into a question: how could I improve a well known algorithm that gets the smallest or the largest number in an array by using built-in Math methods such as Math.min and Math.max. For those not familiar with these methods, they return [...]]]></description> <content:encoded><![CDATA[<p>This morning while commuting to the office, reading <a href="http://www.javascriptrules.com/books/#nicholaszakas-professionaljavascript" target="_blank">JavaScript for Web Developers</a>, I bumped into a question: how could I improve a well known algorithm that gets the smallest or the largest number in an array by using built-in Math methods such as <code><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Math/min" target="_blank">Math.min</a></code> and <code><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Math/max" target="_blank">Math.max</a></code>. For those not familiar with these methods, they return the smallest or the largest number respectively from a list of zero or more numbers passed as parameters, e.g.: <code>Math.min(4,3,9,6)</code> returns 3, <code>Math.max(4,3,9,6)</code> returns 9. I was wondering if calling such methods using <code>apply</code> and an <code>Array</code> as argument would work. I could hardly wait to get to the office to test it out on my <a href="http://getfirebug.com/" target="_blank">Firebug</a> console. I first tried:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Math.<span style="color: #660066;">max</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>Math<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>And bingo! It works!</p><p><span id="more-213"></span><br /><h3>Previous work</h3><p>Since it seemed so easy I thought that somebody else would had already figured this out before and I did a <a href="http://search.yahoo.com/search?p=Math.max.apply" target="_blank">quick search</a> for <code>Math.max.apply</code> and *bam!*: the first occurrence was a <a href="http://ejohn.org/blog/fast-javascript-maxmin/" target="_blank">John Resig&#8217;s post</a> back in 07&#8217;s where he describes such technique for augmenting <code>Array</code> type. Really handy.</p><h3>Performance</h3><p>My main concern to decide whether to use this technique was its performance, so I ran a quick test comparing it to a very popular <code>for</code> loop algorithm and an optimized loop for a given array of random numbers:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">,</span> max<span style="color: #339933;">,</span>
    a <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    len <span style="color: #339933;">=</span> 1e4<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* create an array of ten thousand random numbers */</span>
console.<span style="color: #660066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'array creation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> 1e4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
console.<span style="color: #660066;">timeEnd</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'array creation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* for loop */</span>
max <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>Infinity<span style="color: #339933;">;</span>
console.<span style="color: #660066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'for loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> max<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        max <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
console.<span style="color: #660066;">timeEnd</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'for loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* optimized loop */</span>
max <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>Infinity<span style="color: #339933;">;</span>
i <span style="color: #339933;">=</span> len<span style="color: #339933;">;</span>
console.<span style="color: #660066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'optimized loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> max<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        max <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
console.<span style="color: #660066;">timeEnd</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'optimized loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* Math.max */</span>
console.<span style="color: #660066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Math.max'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
max <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>Math<span style="color: #339933;">,</span> a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">timeEnd</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Math.max'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Running this code on my firebug console (Firefox 3.0.14), I got the same largest number on each technique within the array as expected and the following times:</p><ul><li>array creation: <strong>89ms</strong></li><li>for loop: <strong>29ms</strong></li><li>optimized loop: <strong>20ms</strong></li><li>Math.max: <strong>1ms</strong></li></ul><p>Wow! This is pretty fast! Huh? You can copy the code above and paste on your firebug console in order to get your own results or you can <a href="http://sandbox.javascriptrules.com/fastminmax/" target="_blank">check it out here</a>.</p><h3>Conclusion</h3><p>This technique deserves lots of credit for its simplicity and speed, it&#8217;s those one-line codes that beats any fancy and complex algorithm that once you get to know, you start using every time you need, however it&#8217;s not true for all browsers :-(</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/N5tcfxuf93Q" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/09/23/fast-minmax-in-arrays/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/09/23/fast-minmax-in-arrays/</feedburner:origLink></item> <item><title>WebKit Page Cache</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/MuFd08fwzhM/</link> <comments>http://www.javascriptrules.com/2009/09/17/webkit-page-cache/#comments</comments> <pubDate>Thu, 17 Sep 2009 20:14:32 +0000</pubDate> <dc:creator>Rafael Coelho</dc:creator> <category><![CDATA[browser]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[WebKit cache]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=209</guid> <description><![CDATA[Performance on the web has always been a hot topic to talk about specially when you talk about page load, but you don&#8217;t see as often people talking about perceived load which is related to how fast the interface responds to the user interaction, in this area WebKit based browsers like Safari and Chrome from [...]]]></description> <content:encoded><![CDATA[<p>Performance on the web has always been a hot topic to talk about specially when you talk about page load, but you don&#8217;t see as often people talking about perceived load which is related to how fast the interface responds to the user interaction, in this area <a href="http://en.wikipedia.org/wiki/WebKit#Browser_version_summary" target="_blank">WebKit based browsers</a> like Safari and Chrome from my point of view have always been ahead.</p><p><span id="more-209"></span>In the article <a href="http://webkit.org/blog/427/webkit-page-cache-i-the-basics/" target="_blank">WebKit Page Cache I – The Basics</a> Brady Eidson talks about the Page Cache feature on WebKit, as he stated it&#8217;s not about caching in the HTTP sense, storing raw files on disk or even caching resources in memory. &#8220;More simply, when you leave the page we <em>pause</em> it and when you come back we press <em>play</em>.&#8221;, this totally affects the perceived performance, when you hit the back button, even if you have files cached locally the browser will still have to load it again, run all your scripts, recreate the DOM and so on, so basically &#8220;When the Page Cache works it makes clicking the back button almost instantaneous.&#8221;</p><p>The last time they updated Page Cache was back in &#8216;02 the web  has evolved a lot since then and it&#8217;s not easy to keep up to date, you have to take in considetration HTTPS, plugins, frames, page events, although some of these issues have been fixed already like the frames problem, it still a long way to go, anyway it&#8217;s great to see that they are working on it.</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/MuFd08fwzhM" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/09/17/webkit-page-cache/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/09/17/webkit-page-cache/</feedburner:origLink></item> <item><title>String searching algorithms in JavaScript engines</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/ILbmKJblgqw/</link> <comments>http://www.javascriptrules.com/2009/08/12/string-searching-algorithms-in-javascript-engines/#comments</comments> <pubDate>Wed, 12 Aug 2009 03:05:34 +0000</pubDate> <dc:creator>Marcel Duran</dc:creator> <category><![CDATA[algorithm]]></category> <category><![CDATA[browser]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[boyer-moore]]></category> <category><![CDATA[ecma]]></category> <category><![CDATA[ecmascript]]></category> <category><![CDATA[indexOf]]></category> <category><![CDATA[javascriptcore]]></category> <category><![CDATA[kjs]]></category> <category><![CDATA[naïve]]></category> <category><![CDATA[spidermonkey]]></category> <category><![CDATA[string]]></category> <category><![CDATA[tracemonkey]]></category> <category><![CDATA[v8]]></category> <category><![CDATA[webkit]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=125</guid> <description><![CDATA[I&#8217;ve just finished chapter 7: Writing Efficient JavaScript by Nicholas Zakas on Steve Souders&#8216; new book, Even Faster Web Sites, where he presents several string optimization techniques to improve JavaScript performance and wondered which algorithm does String.indexOf method implements on JavaScript engines (aka ECMAScript engines). A few months ago I&#8217;ve asked this question to Yahoo! fellow [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve just finished chapter 7: Writing Efficient JavaScript by <a href="http://www.nczonline.net/" target="_blank">Nicholas Zakas</a> on <a href="http://stevesouders.com/" target="_blank">Steve Souders</a>&#8216; new book, <a href="http://www.javascriptrules.com/books/#stevesouders-evenfaster" target="_blank">Even Faster Web Sites</a>, where he presents several string optimization techniques to improve JavaScript performance and wondered which algorithm does <code>String.indexOf</code> method implements on <a href="http://en.wikipedia.org/wiki/JavaScript_engine" target="_blank">JavaScript engines</a> (aka <a href="http://en.wikipedia.org/wiki/List_of_ECMAScript_engines" target="_blank">ECMAScript engines</a>).<br /> A few months ago I&#8217;ve asked this question to Yahoo! fellow <a href="http://crockford.com/" target="_blank">Douglas Crockford</a> and he said the ECMAScript standard does not require a specific algorithm, so it could vary with each browser. You can check that on section 15.5.4.7 of <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" target="_blank">Standard ECMA-262</a>. I decided then to download the most popular open-source JavaScript engines source codes and found mainly 3 algorithms:</p><p><span id="more-125"></span><ul><li><a href="http://en.wikipedia.org/wiki/String_searching_algorithm#Na.C3.AFve_string_search" target="_blank">Naïve</a>: simple and least inefficient way to search in strings, it basically checks every position in the haystack then every position of the needle. The advantage of using this algorithm is that it needs no initial overhead such as auxiliary tables creation. It has O(mn) complexity, where m is the needle length and n the haystack length.</li><li><a href="http://en.wikipedia.org/wiki/Boyer_moore" target="_blank">Boyer-Moore</a>: Efficient searching string algorithm that preprocesses the needle and doesn&#8217;t check every position in the haystack but rather skips some of them on each unsuccessful attempt. It has O(n) complexity with O(3n) in the worst case.</li><li><a href="http://en.wikipedia.org/wiki/Boyer-Moore-Horspool_algorithm" target="_blank">Boyer-Moore-Horspool</a>: It&#8217;s a simplification of Boyer-Moore&#8217;s algorithm with less overhear during initial needle preprocessing. It also has O(n) complexity but O(mn) in the worst case.</li></ul><h3>Algorithms by engines</h3><p>The <code>String.indexOf</code> algorithms by JavaScript engines follows:</p><table border="0"><tr><th>JavaScript Engine</th><th>Layout Engine</th><th>Browsers</th><th>String.indexOf algorithm</th></tr><tr><td><a href="https://developer.mozilla.org/en/SpiderMonkey" target="_blank">SpiderMonkey</a></td><td><a href="http://www.mozilla.org/newlayout/" target="_blank">Gecko</a></td><td>Firefox up to 3.0.*</td><td>Boyer-Moore-Horspool</td></tr><tr><td><a href="https://wiki.mozilla.org/JavaScript:TraceMonkey" target="_blank">TraceMonkey</a></td><td><a href="http://www.mozilla.org/newlayout/" target="_blank">Gecko</a></td><td>Firefox from 3.1.*</td><td>Boyer-Moore-Horspool</td></tr><tr><td><a href="http://api.kde.org/4.0-api/kdelibs-apidocs/kjs/html/index.html" target="_blank">KJS</a></td><td><a href="http://www.konqueror.org/features/browser.php" target="_blank">KHTML</a></td><td>Konqueror</td><td>Naïve</td></tr><tr><td><a href="http://webkit.org/projects/javascript/" target="_blank">JavaScriptCore</a></td><td><a href="http://webkit.org/" target="_blank">WebKit</a></td><td>Safari up to 3.*</td><td>Naïve</td></tr><tr><td><a href="http://trac.webkit.org/wiki/SquirrelFish" target="_blank">SquirrelFish</a></td><td><a href="http://webkit.org/" target="_blank">WebKit</a></td><td>Safari from 4.*</td><td>Naïve</td></tr><tr><td><a href="http://msdn.microsoft.com/en-us/library/hbxc2t98(VS.85).aspx" target="_blank">JScript</a></td><td><a href="http://msdn.microsoft.com/en-us/library/aa741317(VS.85).aspx" target="_blank">Trident</a></td><td>Internet Explorer</td><td>?</td></tr><tr><td><a href="http://code.google.com/p/v8/" target="_blank">V8</a></td><td><a href="http://webkit.org/" target="_blank">WebKit</a></td><td>Chrome</td><td>Strategy: Naïve, Boyer-Moore-Horspool and Boyer-Moore</td></tr><tr><td>Linear B</td><td><a href="http://en.wikipedia.org/wiki/Presto_(layout_engine)" target="_blank">Presto</a></td><td>Opera 7.0 &#8211; 9.50[</td><td>?</td></tr><tr><td>Futhark</td><td><a href="http://dev.opera.com/articles/view/presto-2-2-and-opera-10-a-first-look/" target="_blank">Presto Core 2</a></td><td>Opera from 9.50</td><td>?</td></tr><tr><td><a href="http://www.mozilla.org/rhino/" target="_blank">Rhino</a></td><td>-</td><td>-</td><td>java.lang.String.indexOf</td></tr></table><h4>SpiderMonkey</h4><p>Implements the <code>String.indexOf</code> in C with some verifications in string lengths prior to run BMH algorithm in order to avoid long searching for relatively small strings.</p><p>Source code available at: <a href="ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.0.13/source/firefox-3.0.13-source.tar.bz2" target="_blank">ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.0.13/source/firefox-3.0.13-source.tar.bz2</a></p><h4>TraceMonkey</h4><p>It has exactly the same <code>String.indexOf</code> implementation as SpiderMonkey but in C++.</p><p>Source code available at: <a href="ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.5.2/source/firefox-3.5.2-source.tar.bz2" target="_blank">ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.5.2/source/firefox-3.5.2-source.tar.bz2</a></p><h4>KJS</h4><p>The main part of the naïve implementation of <code>indexOf</code> follows*:</p><div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/* ... */</span>
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> UChar<span style="color: #000040;">*</span> c <span style="color: #000080;">=</span> data_ <span style="color: #000040;">+</span> pos<span style="color: #008080;">;</span> c <span style="color: #000080;">&lt;=</span> end<span style="color: #008080;">;</span> c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>c<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>uc <span style="color: #000080;">==</span> fchar <span style="color: #000040;">&amp;&amp;</span> <span style="color: #000040;">!</span><span style="color: #0000dd;">memcmp</span><span style="color: #008000;">&#40;</span>c <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span>, fdata, fsizeminusone<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>c <span style="color: #000040;">-</span> data_<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span></pre></div></div><p><em>* taken from KDE 4.0 API reference</em></p><p>Files related to <code>String.indexOf</code> method:</p><ul><li>string_object.cpp: defines the prototype for String object where <code>indexOf</code> is in a switch case statement and calls <code>find</code> function.</li><li>ustring.cpp: defines the <code>find</code> function where the naïve algorithm is implemented.</li></ul><p>Browse the source code online: <a href="http://api.kde.org/4.0-api/kdelibs-apidocs/kjs/html/files.html" target="_blank">http://api.kde.org/4.0-api/kdelibs-apidocs/kjs/html/files.html</a></p><h4>JavaScriptCore &#038; SquirrelFish</h4><p>These engines are known as JavaScriptCore in WebKit Project and was originally derived from KJS, hence still shares the same algorithm for <code>String.indexOf</code>.</p><p>Files related to <code>String.indexOf</code> method:</p><ul><li>root/trunk/JavaScriptCore/runtime/StringPrototype.cpp: this is where <code>indexOf</code> method is defined and call <code>find</code> function</li><li>root/trunk/JavaScriptCore/runtime/UString.cpp: look for <code>find</code> function</li></ul><p>Source code available at: <a href="http://webkit.org/building/checkout.html" target="_blank">http://webkit.org/building/checkout.html</a><br /> Browse the source code online: <a href="http://trac.webkit.org/browser" target="_blank">http://trac.webkit.org/browser</a></p><h4>V8</h4><p>A very smart strategy is applied to the string searching in order to choose the best algorithm based on the length of the needle:</p><ul><li>First of all it checks if there is a non-ASCII needle for an ASCII haystack and bail out if there is.</li><li>Checks if the needle length is less than 5 then uses a naïve solution called <code>simpleIndexOf</code>, because the max shift of Boyer-Moore on such needle length doesn&#8217;t compensate for the overhead. This <code>simpleIndexOf</code> function never bails out, it means that the needle will be checked for a match in the whole haystack.</li><li>If the needle length is greater than or equals to 5 another <code>simpleIndexOf</code> function is called. This one considers how much work have been done (unsuccessful matches) in order to stop trying and switch for a better algorithm. This is called the &#8220;badness count&#8221; which once reached the max, stop the search and returns the index in the haystack where the next algorithm should continue from.</li><li>The next algorithm in the strategy chain is Boyer-Moore-Horspool which also consider the badness count prior to jump to the next algorithm.</li><li>The last one is Boyer-Moore which has some initial overhead when creating good and bad shift tables.</li></ul><p>Source code available at: <a href="http://code.google.com/p/v8/wiki/Source?tm=4" target="_blank">http://code.google.com/p/v8/wiki/Source?tm=4</a></p><h4>Rhino</h4><p>Rhino runs on top of Java Virtual Machine and uses the <code>java.lang.String.indexOf</code> from Java language implemented for such JVM. Interestingly there is a comment saying:</p><p>&#8220;Uses Java String.indexOf(). OPT to add &#8211; BMH searching from jsstr.c&#8221;.</p><p>Where jsstr.c is the file for SpiderMonkey JavaScript String implementation. Implementing such algorithm in Java might degrade the search performance, unless the <code>java.lang.String.indexOf</code> implementation is much worse than that.</p><p>Source code available at: <a href="http://www.mozilla.org/rhino/download.html" target="_blank">http://www.mozilla.org/rhino/download.html</a></p><h4>Other engines</h4><p>What about Internet Explorer, Opera and other browsers JavaScript engines? As they aren&#8217;t open-source projects I could not check their codes out. :-(</p><h3>Benchmark</h3><p>By running a simple test across some browsers we can have an idea how fast/slow is <code>String.indexOf</code> on some JavaScript engines although this doesn&#8217;t necessarily mean an algorithm is better than another because the performance of the engine itself might affect the outcome.<br /> The test consists of the average of a 100 times running a search for the word &#8220;<em>foobar</em>&#8221; in the middle of a ~1200 length &#8220;<em>ipsum lorem</em>&#8221; text iterating 1 million times each search. <a href="http://sandbox.javascriptrules.com/indexof/" target="_blank">Try it</a> yourself.</p><p>The results in the follow table were taken by running this test on the same machine (Pentium 4HT, 3GHz, 1Gb RAM, Windows XP SP3).</p><table><tr><th>JavaScript Engine</th><th>Browser</th><th>Version</th><th>Average (ms)</th></tr><tr><td>V8</td><td>Chrome</td><td>2.0.172.39</td><td class="right">827.66</td></tr><tr><td>SpiderMonkey</td><td>Firefox</td><td>3.0.13</td><td class="right">947.97</td></tr><tr><td>TraceMonkey</td><td>Firefox</td><td>3.5.2</td><td class="right">1169.25</td></tr><tr><td>SquirrelFish</td><td>Safari</td><td>4.0.2</td><td class="right">1207.02</td></tr><tr><td>KJS*</td><td>Konqueror</td><td>4.2.2</td><td class="right">1361.59</td></tr><tr><td>SpiderMonkey</td><td>Firefox</td><td>2.0.0.20</td><td class="right">1456.57</td></tr><tr><td>Futhark</td><td>Opera</td><td>10.00 beta 2</td><td class="right">1549.06</td></tr><tr><td>Futhark</td><td>Opera</td><td>9.64</td><td class="right">1613.02</td></tr><tr><td>JScript**</td><td>Internet Explorer</td><td>8.0</td><td class="right">3101.23</td></tr><tr><td>Rhino***</td><td>-</td><td>-</td><td class="right">4103.64</td></tr><tr><td>JScript</td><td>Internet Explorer</td><td>6.0</td><td class="right">4479.82</td></tr><tr><td>JScript</td><td>Internet Explorer</td><td>7.0</td><td class="right">4515.08</td></tr></table><p><em>* running on the same machine with Ubuntu 9.04 live cd</em><br /> <em>** running on a VM on a different computer</em><br /> <em>*** running on Sun JRE 6 &#8211; 1.6.0_14</em></p><p>Again, these results don&#8217;t prove which algorithm is the best due to different browser performances, however it is worth noting that Firefox 3.0.13 performed better than Firefox 3.5.2 on this benchmark. Internet Explorer had the worst results, it can be either the algorithm or the browser performance itself or even both. :-)</p> <img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/ILbmKJblgqw" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/08/12/string-searching-algorithms-in-javascript-engines/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/08/12/string-searching-algorithms-in-javascript-engines/</feedburner:origLink></item> <item><title>CSS color brightness contrast using JavaScript</title><link>http://feedproxy.google.com/~r/JavaScriptRules/~3/Pr63V983xU4/</link> <comments>http://www.javascriptrules.com/2009/08/05/css-color-brightness-contrast-using-javascript/#comments</comments> <pubDate>Wed, 05 Aug 2009 00:24:28 +0000</pubDate> <dc:creator>Marcel Duran</dc:creator> <category><![CDATA[css]]></category> <category><![CDATA[greasemonkey]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[brightness]]></category> <category><![CDATA[color]]></category> <category><![CDATA[contrast]]></category> <category><![CDATA[rgb]]></category><guid isPermaLink="false">http://www.javascriptrules.com/?p=109</guid> <description><![CDATA[Dealing with foreground/background color contrast can be a bit tricky specially when you are a not a color-theory savvy or when using CSS color names as listed by Douglas Crockford&#8217;s page. The most common problem is when you have to place a label over a color you don&#8217;t know on beforehand, it can either be an [...]]]></description> <content:encoded><![CDATA[<p>Dealing with foreground/background color contrast can be a bit tricky specially when you are a not a color-theory savvy or when using CSS color names as listed by <a href="http://www.crockford.com/wrrrld/color.html" target="_blank">Douglas Crockford&#8217;s page</a>.<br /> The most common problem is when you have to place a label over a color you don&#8217;t know on beforehand, it can either be an arbitrary color chosen by the user or come from a random-color generator function and sometimes from a long list in a datasource. Usually you have to decide between labeling it in black or white. When a color is too bright, a black label over it might be the best choice but definitely won&#8217;t be good over a very dark color, it can be really hard to read it, a white label should work better.</p><p><span id="more-109"></span>W3C advises:</p><blockquote><p>Ensure that foreground and background color combinations provide sufficient contrast when viewed by someone having color deficits or when viewed on a black and white screen.</p></blockquote><p>And suggests the following <a href="http://www.w3.org/WAI/ER/WD-AERT/#color-contrast" target="_blank">algorithm</a>* to calculate the perceived brightness of a color:</p><p><code>brightness = ((REDvalue X 299) + (GREENvalue X 587) + (BLUEvalue X 114)) / 1000</code></p><p>If the perceived brightness is greater than 125, choose black, otherwise white.</p><p><em>* This algorithm is taken from a formula for converting RGB values to YIQ values.</em></p><p>On Doug&#8217;s CSS color names page, he listed all color names alphabetically in two columns, the first one uses a black label over the colors and the second one uses white. I have created a <a href="http://www.greasespot.net/" target="_blank">Greasemonkey</a> script that adds a third column to that page applying this brightness algorithm that decides between black and white which one works better over each color in the list. You can <a href="http://userscripts.org/scripts/show/53262" target="_blank">get and install the script here</a>.</p><p><a href="http://www.crockford.com/wrrrld/color.html" target="_blank"><img src="http://cdn-javascriptrules.2static.it/i/posts/doug-css-colors.png" alt="Doug's CSS color names page with the Greasemonkey script" /></a><br /> <em>Doug&#8217;s CSS color names page with the Greasemonkey script</em></p><p>To get the RGB values from an element&#8217;s background color you can use the <code>window.getComputedStyle</code>* method as follows:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'foobar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    rgb <span style="color: #339933;">=</span> window.<span style="color: #660066;">getComputedStyle</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">;</span></pre></div></div><p><em>* Use <code>currentStyle</code> on IE, see <a href="http://www.quirksmode.org/dom/getstyles.html" target="_blank">&#8220;Get Styles on PPK&#8217;s QuirksMode&#8221;</a></em></p><p>This will bring the RBG values list string in the format: &#8220;rgb(255, 255, 255)&#8221; for a white background color. You can use a regular expression and apply it over the RGB string in order to parse its values:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> re <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/rgb\((\d+), (\d+), (\d+)\)/</span><span style="color: #339933;">;</span>
rgb <span style="color: #339933;">=</span> re.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>rgb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>The <code>rgb</code> variable now has an array with the split background RGB color values, you can get the separated R, G and B values from the index 1 of the array:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span>
    r <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>rgb<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    g <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>rgb<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    b <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>rgb<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Finally calculate the color brightness:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> brightness <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>r<span style="color: #339933;">*</span><span style="color: #CC0000;">299</span> <span style="color: #339933;">+</span> g<span style="color: #339933;">*</span><span style="color: #CC0000;">587</span> <span style="color: #339933;">+</span> b<span style="color: #339933;">*</span><span style="color: #CC0000;">114</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>brightness <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">125</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// use black</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: #006600; font-style: italic;">// use white</span>
<span style="color: #009900;">&#125;</span></pre></div></div><img src="http://feeds.feedburner.com/~r/JavaScriptRules/~4/Pr63V983xU4" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.javascriptrules.com/2009/08/05/css-color-brightness-contrast-using-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.javascriptrules.com/2009/08/05/css-color-brightness-contrast-using-javascript/</feedburner:origLink></item> </channel> </rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: www.javascriptrules.com @ 2010-08-29 15:09:37 -->
