<?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>A Log on JavaScript &#187; Uncategorized</title>
	<atom:link href="http://www.jslog.com/category/uncategorized/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jslog.com</link>
	<description></description>
	<lastBuildDate>Thu, 21 Jul 2011 11:00:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Testing ExtJS with Selenium &#8211; Automating UI Tests</title>
		<link>http://www.jslog.com/testing-extjs-with-selenium-automating-ui-tests</link>
		<comments>http://www.jslog.com/testing-extjs-with-selenium-automating-ui-tests#comments</comments>
		<pubDate>Wed, 14 Jul 2010 17:00:33 +0000</pubDate>
		<dc:creator>radu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[quick tips]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.jslog.com/?p=217</guid>
		<description><![CDATA[Automation testing of UI is essential in any big project, but it is difficult to achieve this for user interfaces built with ExtJS. Selenium records user actions, by clicks on elements, and memorizes the ids of the selected elements. Yet since ExtJS auto-generates ids which are not guaranteed to stay the same, you cannot rely [...]]]></description>
			<content:encoded><![CDATA[<p>Automation testing of UI is essential in any big project, but it is difficult to achieve this for user interfaces built with ExtJS. Selenium records user actions, by clicks on elements, and memorizes the ids of the selected elements. Yet since ExtJS auto-generates ids which are not guaranteed to stay the same, you cannot rely on this. The same problem is when you simply add a small change (add a label, etc), so the generation (if you relied on it to be the same) will totally change and the automated tests will be ruined.
</p>
<p>
Instead, <b>Selenium tests for ExtJS should rely on CSS selectors</b>. For every button, grid, label, tab or any significant UI element, I simply chose to use the <strong>cls</strong> attribute and specify a CSS class.</p>
<pre class="prettyprint">
new Ext.Button({
    text: 'Ok',
    cls: 'seleniumOkButton', //can have more classes, separated by space
    scope: this,
    handler: function(){ ... }
})
</pre>
<p>This is how a basic button that is used in automation testing looks like. And I use the following XPath selector in Selenium:</p>
<pre class="prettyprint">
//table[contains(@class,'seleniumOkButton')]
</pre>
</p>
<p>Happy automated testing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jslog.com/testing-extjs-with-selenium-automating-ui-tests/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Google Closure Advanced Compilation</title>
		<link>http://www.jslog.com/google-closure-advanced-compilation</link>
		<comments>http://www.jslog.com/google-closure-advanced-compilation#comments</comments>
		<pubDate>Sun, 21 Mar 2010 21:24:10 +0000</pubDate>
		<dc:creator>radu</dc:creator>
				<category><![CDATA[Google Closure]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[utilities]]></category>
		<category><![CDATA[js code optimization]]></category>
		<category><![CDATA[obfuscation]]></category>

		<guid isPermaLink="false">http://www.jslog.com/?p=171</guid>
		<description><![CDATA[As I have promised in this post, I am giving a review of the ADVANCED_OPTIMIZATIONS option in Google Closure JavaScript Compiler.
Beyond simply shortening variable names, Closure Compiler with ADVANCED_OPTIMIZATIONS, does three other important steps:

aggresive renaming &#8211; not only renaming local variables and functions, but it renames GLOBAL variables and functions. In this way, it can [...]]]></description>
			<content:encoded><![CDATA[<p>As I have promised in <a href="http://www.jslog.com/using-google-closure-compiler">this</a> post, I am giving a review of the <code>ADVANCED_OPTIMIZATIONS</code> option in Google Closure JavaScript Compiler.</p>
<p>Beyond simply shortening variable names, Closure Compiler with ADVANCED_OPTIMIZATIONS, does three other important steps:</p>
<ul>
<li><b>aggresive renaming</b> &#8211; not only renaming local variables and functions, but it renames GLOBAL variables and functions. In this way, it can ruin your public API</li>
<li><b>dead code removal</b> &#8211; it removes functions you are not using and segments of unreachable code. This can be fine for some apps, but it is definitely risky for JavaScript libraries, that expose some functions which are supposed to be called only by client code.</li>
<li><b>function inlining</b> &#8211; inserting the function&#8217;s body instead of the function call, where appropriate</li>
</ul>
<p>So it is true that without some additional work, the ADVANCED_OPTIMIZATIONS option will just ruin your code and your public API. Of course the solutions are at hand, but the question is if they worth the effort.
</p>
<p><span id="more-171"></span></p>
<p>
<h3>Keep your public API</h3>
<p>If you provide ONLY the code below to Google Compiler, it produces <b>empty</b> output:</p>
<pre class="prettyprint">
function hello(name){
    alert("Hello " + name);
}
</pre>
<p>What? Empty output? Well&#8230; yes, as you never call your function. Instead, for the next code: </p>
<pre class="prettyprint">
function hello(name){
    alert("Hello " + name);
}
hello('jslog');
</pre>
<p>it produces the following output:</p>
<pre class="prettyprint">
alert("Hello jslog");
</pre>
<p>This is smart! But we want to preserve our API (by the way, in the tutorial for Google Closure Compiler Advanced Optimizations, <a href="http://code.google.com/closure/compiler/docs/api-tutorial3.html">Google says on this page</a> that the <code>hello</code> function is preserved, while it is NOT &#8211; see section <a href="http://code.google.com/closure/compiler/docs/api-tutorial3.html#removal">Removal of code you want to keep</a> and try the code online at <a href="http://closure-compiler.appspot.com/home">Closure Compiler UI Tool</a>)
</p>
<p>
So if the <code>hello</code> method above would be part of the public API, it would break third parties using it. Google proposes a solution for this: export the public objects/functions into the global namespace using the <code>window</code> object:</p>
<pre class="prettyprint">
function hello(name){
    alert("Hello " + name);
}
hello('jslog');
window['hello'] = hello;

//and the output is:
function a(b){alert("Hello "+b)}a("jslog");window.hello=a;
//so the hello function is kept as a property on the global window object
</pre>
<p>Instead, if you use:</p>
<pre class="prettyprint">
window.hello = hello;
</pre>
<p>you get </p>
<pre class="prettyprint">
function b(c){alert("Hello "+c)}b("jslog");window.a=b;
</pre>
<p>which is surely not what you want. So make sure you use the <code>window['public_name']</code> notation. You should also standardize the way you access properties in your objects, either using the array notation, or the dotted notation, otherwise the compiler could be mislead by a mix of the two. But sometimes we just need to use both, as properties may be automatically generated at runtime.
</p>
<p>Other problems with the <b>Google Closure Compiler</b> <code>ADVANCED_OPTIMIZATIONS</code> are separately compiling blocks of code with dependencies to external JavaScript. The solution for this is </p>
<ul>
<li>using either <b>exports</b> like the above or with the <code>goog.exportSymbol()</code> or</li>
<li>using extern files specifically provided as a compilation option</li>
</ul>
<p>In any case, I think this is just a bit too clumsy. </p>
<p>Moreover, having a class and export all its properties/functions is quite a job to to if your app is already a large one. Just have a short example:</p>
<pre class="prettyprint">
MyClass = function(name) {
  this.myName = name;
};
MyClass.prototype.myMethod = function() {
  alert(this.myName);
};
window['MyClass'] = MyClass; // <-- Constructor
MyClass.prototype['myMethod'] = MyClass.prototype.myMethod; <-- export mechanism

//the above compiles to
MyClass=function(a){this.b=a};MyClass.prototype.a=function(){alert(this.b)};window.MyClass=MyClass;MyClass.prototype.myMethod=MyClass.prototype.a;
</pre>
</p>
<p>
<h3>Conclusions</h3>
<p>After this short overview of the <code>ADVANCED_OPTIMIZATIONS</code> flag, I really think most people won't need it. If you already have a large library, having it compiled with advanced optimizations would be a total nightmare, as it would require a review of all public methods and properties and additional work for each. And the gain? Just a few kilobytes. I have tried compiling <b>ExtJS Core with advanced optimizations and got aprox 62 KB</b>, while with <b>simple optimizations it is 74 KB</b>. Not very well for the amount of effort it would require, in my opinion. </p>
<p>But if you still think advanced optimizations is for you, you are probably wanting to optimize a lot, and you should first start seaching for other ways to optimize - first, make sure you combine all your js code into one file. It's better to have one js file of 100KB rather than have 10 files each of 5 KB. So make sure you are doing every other possible optimization before moving to the advanced optimizations flag.</p>
<p>After all, it's up to you to decide if it's worth the effort!
</p>
<p>PS: You can follow me on twitter <a href="http://twitter.com/extjslog">@extjslog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jslog.com/google-closure-advanced-compilation/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Logging management utility library</title>
		<link>http://www.jslog.com/logging-management-utility-library</link>
		<comments>http://www.jslog.com/logging-management-utility-library#comments</comments>
		<pubDate>Thu, 31 Dec 2009 09:45:20 +0000</pubDate>
		<dc:creator>radu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[utilities]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.jslog.com/?p=44</guid>
		<description><![CDATA[I have developed a small utility library, which helps with managing logging of your JavaScript applications.
Here are some features it supports:

Turn logging on and off
Support for Firebug console and log4javascript
Redefine console.log, console.warn, &#8230; (all console logging methods) through methods from log4javascript, if console is not detected

All you have to do is to keep on logging [...]]]></description>
			<content:encoded><![CDATA[<p>I have developed a small utility library, which helps with managing logging of your JavaScript applications.<br />
Here are some features it supports:</p>
<ul>
<li>Turn logging on and off</li>
<li>Support for Firebug console and log4javascript</li>
<li>Redefine console.log, console.warn, &#8230; (all console logging methods) through methods from log4javascript, if console is not detected</li>
</ul>
<p>All you have to do is to keep on logging with firebug just as you did before! The problem occurs when you want to debug n a browser that doesn&#8217;t have Firebug enabled! Well, that should be no problem! Just include <code>jslog.js</code> and <code>log4javascript-1.4.1.js</code> and all logging that goes through console.log will now appear to the popup window log4javascript creates!</p>
<p>So jslog.js is a nice utility which allows you to work with two logging strategies, but using a single API, which you already know, the Firebug console</p>
<p>Another facility is disabling logging &#8211; in one single line! This is especially useful when going live! You don&#8217;t want to go through all your code and modify it! Use jslog.logging.init(false)</p>
<p>A small tutorial.<br />
Include     &lt;script type=&#8221;text/javascript&#8221; src=&#8221;jslog.js&#8221;&gt;&lt;/script&gt;</p>
<pre class="prettyprint">
    jslog.logging.init(true);
    console.log('hello','this will be logged');

    jslog.logging.init(false);
    console.warn('sorry...','this log will not appear');
</pre>
<p>When you want to log in non-firebug environments, just include the following in your html file:<br />
    &lt;script type=&#8221;text/javascript&#8221; src=&#8221;log4javascript.js&#8221;&gt;&lt;/script&gt;<br />
    &lt;script type=&#8221;text/javascript&#8221; src=&#8221;jslog.js&#8221;&gt;&lt;/script&gt;</p>
<pre class="prettyprint">
//You don't have to change your code.
//if jslog.js detects no console to be available,
//it creates one and redirects logging to log4javascript
    jslog.logging.init(true);
    console.log('hello','this will be logged');

    jslog.logging.setEnabled(false);
    console.warn('sorry...','this log will not appear');
</pre>
<p>If log4javascript.js is not included in the page and no Firebug console is detected, jslog will detect this and will just be silent, even if logging is enabled. It will not throw an error!
</p>
<p><a href="http://jslog.com/download/jslog-1.0.zip"><strong>Download it here!</strong></a></p>
<p>So&#8230;. happy logging! For questions and support, <a href="http://jslog.com/about">contact me!</a></p>
<p>Credits to <a href="http://log4javascript.org/">Tim Down for his awesome log4javascript library</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jslog.com/logging-management-utility-library/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello JS World</title>
		<link>http://www.jslog.com/hello-js-world</link>
		<comments>http://www.jslog.com/hello-js-world#comments</comments>
		<pubDate>Wed, 23 Dec 2009 21:01:41 +0000</pubDate>
		<dc:creator>radu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jslog.com/?p=6</guid>
		<description><![CDATA[console.log('jslog.com')
]]></description>
			<content:encoded><![CDATA[<p><code>console.log('jslog.com')</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jslog.com/hello-js-world/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

