<?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>bojanpejic.com &#187; compressor</title>
	<atom:link href="http://bojanpejic.com/tag/compressor/feed/" rel="self" type="application/rss+xml" />
	<link>http://bojanpejic.com</link>
	<description>Scrap Book About Web – Programming – Development – Places, and more 8-)</description>
	<lastBuildDate>Sun, 16 May 2010 14:37:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Compress JavaScript with Google Closure</title>
		<link>http://bojanpejic.com/compress-javascript-with-google-closure/</link>
		<comments>http://bojanpejic.com/compress-javascript-with-google-closure/#comments</comments>
		<pubDate>Sun, 16 May 2010 14:37:56 +0000</pubDate>
		<dc:creator>bojan</dc:creator>
				<category><![CDATA[Apps and Software]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[compressor]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[minify]]></category>

		<guid isPermaLink="false">http://bojanpejic.com/?p=140</guid>
		<description><![CDATA[Google Closure is  a set of closure tools which contains a JavaScript optimizer, a comprehensive JavaScript library and a templating system for JavaScript &#38; Java. It&#8217;s available on Google Code page. In this post will focus on JavaScript optimizer and how can we optimize a JavaScript file, and if you interested in other possibilities of...]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-142 alignleft" title="google-closure" src="http://bojanpejic.com/wp-content/uploads/2010/05/google-closure.png" alt="" width="151" height="143" />Google Closure is  a set of closure tools which contains a JavaScript optimizer, a comprehensive JavaScript library and a templating system for JavaScript &amp; Java. It&#8217;s available on <a title="Google Closure" href="http://code.google.com/closure/" target="_blank">Google Code</a> page. In this post will focus on JavaScript optimizer and how can we optimize a JavaScript file, and if you interested in other possibilities of Closure you should also visit it&#8217;s page. (This post generally continues one of my previous posts <a href="http://bojanpejic.com/how-to-compress-javascript-code/" target="_blank">How to Compress JavaScript code</a>.) There are three methods with we can do our JavaScript optimizing with Google Closure.</p>
<h4>#1 method</h4>
<p>First is the simplest, just visit <a title="Closure compiler online" href="http://closure-compiler.appspot.com/home" target="_blank">closure-compiler.appspot.com</a> and you&#8217;ll get an online Closure Compiler in your browser. There you have to give an URL to your script or paste it to textbox, chose an optimization method from one of the available ones (whitespace, simple or advanced) and if you don&#8217;t know which one to use, chose link to <a href="http://code.google.com/closure/compiler/docs/compilation_levels.html" target="_blank">Which one is right for my code?</a> where is explained how the optimization work. Also you can check from one of the available formatting options, pretty print and print input delimiter. If you check the pretty print formatting option your compiled code will get a formatted code output and not single line one.</p>
<p style="text-align: center;"><img class="size-medium wp-image-153  aligncenter" title="google closure compiler" src="http://bojanpejic.com/wp-content/uploads/2010/05/closurecompiler-300x240.png" alt="" width="300" height="240" /></p>
<h4>#2 method</h4>
<p>Second method is using Closure Compiler Service API! It&#8217;s something like I mentioned in first method. You create a page with a textbox, paste your code and submit it! Form posts your script to Closure Compiler and returns the minified code back to you and shows it. How the HTML code looks? Take a look below or on Closure Compiler page <a href="http://code.google.com/closure/compiler/docs/gettingstarted_api.html" target="_blank">here</a>.</p>
<pre class="brush: xml;">&lt;html&gt;
  &lt;body&gt;
    &lt;form action=&quot;http://closure-compiler.appspot.com/compile&quot; method=&quot;POST&quot;&gt;
    &lt;p&gt;Type JavaScript code to optimize here:&lt;/p&gt;
    &lt;textarea name=&quot;js_code&quot; cols=&quot;50&quot; rows=&quot;5&quot;&gt;
    function hello(name) {
      // Greets the user
      alert('Hello, ' + name);
    }
    hello('New user');
    &lt;/textarea&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;compilation_level&quot; value=&quot;WHITESPACE_ONLY&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;output_format&quot; value=&quot;text&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;output_info&quot; value=&quot;compiled_code&quot;&gt;
    &lt;br&gt;&lt;br&gt;
    &lt;input type=&quot;submit&quot; value=&quot;Optimize&quot;&gt;
    &lt;/form&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<h4>#3 method</h4>
<p>This one is my favorite! It does the same like any other mentioned method before, but with this method you can easily include several files to bi minified/compress to one :) What you need for start is to download <a href="http://code.google.com/closure/compiler/docs/gettingstarted_app.html" target="_blank">Closure Compiler Application</a>. You create a working directory where you put your downloaded Closure Compiler Application. Copy the JavaScript file(s) you want to compile to Closure Compiler working directory, and now let&#8217;s do some compiling!</p>
<p>First example with one input file:</p>
<pre class="brush: plain;">java -jar compiler.jar --js myfile.js --js_output_file myfile.min.js</pre>
<p>Second example with two or more input files:</p>
<pre class="brush: plain;">java -jar compiler.jar --js myfile1.js --js myfile2.js  --js myfile3.js --js_output_file myfile.min.js</pre>
<p>So, through Java we execute the Closure Compiler Application <em>compiler.jar</em>. With option <strong>&#8211;js</strong> we define the input JavaScript file we want to compile, and with <strong>&#8211;js_output_file</strong> is defined the output file name which is compiled. In second example is shown how can be added more than one JavaScript file to be compiled.</p>
<p>For Closure Compiler help type:</p>
<pre class="brush: plain;">java -jar compiler.jar --help</pre>
<p>It is also available setting Closure optimizations through application, if you want to make Advanced optimization:</p>
<pre class="brush: plain;">java -jar compiler.jar --compilation_level ADVENCED_OPTIMIZATIONS --js myfile.js</pre>
<p>I find this Closure Compiler Application very handy, and if I need to compress JavaScript file it is my first choice right now. Maybe it will be interesting in feature to make some compares about sizes of compressed and non-compressed codes, but if you do it online on Closure Compiler page you will see some calculations about size right away. For more details about <a href="http://code.google.com/closure/compiler/" target="_blank">Google Closure Compiler</a> visit it&#8217;s homepage.</p>
]]></content:encoded>
			<wfw:commentRss>http://bojanpejic.com/compress-javascript-with-google-closure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Compress JavaScript Code</title>
		<link>http://bojanpejic.com/how-to-compress-javascript-code/</link>
		<comments>http://bojanpejic.com/how-to-compress-javascript-code/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 10:26:17 +0000</pubDate>
		<dc:creator>bojan</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[compressor]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsmin]]></category>
		<category><![CDATA[minify]]></category>
		<category><![CDATA[packer]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://bojanpejic.com/?p=34</guid>
		<description><![CDATA[In past few months and recently I did some JavaScript coding. The whole source code wasn&#8217;t so big, around 15kB, but it may be growing more, and there are also other JavaScript files which are included in the page and maybe I merge them. To reduce amount of data and in hope to little speed...]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-36 alignright" style="border: 1px solid black;" title="how to compress javascript" src="http://bojanpejic.com/wp-content/uploads/2009/10/howto_compress_javascript.png" alt="how to compress javascript" width="300" height="200" />In past few months and recently I did some JavaScript coding. The whole source code wasn&#8217;t so big, around 15kB, but it may be growing more, and there are also other JavaScript files which are included in the page and maybe I merge them. To reduce amount of data and in hope to little speed up loading of the page I was looking for some options to compress (minify) the source code.</p>
<h3>What means to minify JavaScript?</h3>
<p>One more term which is used for reducing the size of code is <em>minification</em> or <em>minify</em>.</p>
<blockquote><p><strong>Minification</strong> (very often just <strong>minify</strong>, and sometimes also <strong>minimisation</strong> or <strong>minimization</strong>), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code, without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments and sometimes block delimiters; which are used to add readability to the code, but are not required for it to execute. &#8211; wikipedia.org</p></blockquote>
<h3>Why to compress/minify?</h3>
<p>In putting to a simple way the whole quote above, compress (minify) the code to load it faster! Beside that you&#8217;ll reduce the bandwidth consumption of website, and number of HTTP requests if you combine several JavaScript files in one.</p>
<h3>Tools for compress/minify</h3>
<p>Searching over Internet I found several tools which are commonly used for compressing JavaScript code, these tools for compress are:</p>
<ul>
<li><a title="jsmin" href="http://crockford.com/javascript/jsmin" target="_blank">JSMin</a> by Douglas Crockford</li>
<li><a title="Dojo compressor" href="http://dojotoolkit.org/docs/shrinksafe" target="_blank">Dojo compressor</a></li>
<li><a title="JavaScript packer" href="http://dean.edwards.name/packer/" target="_blank">Packer</a> by Dean Edwards</li>
<li><a title="YUI compressor" href="http://developer.yahoo.com/yui/compressor/" target="_blank">YUI compressor</a></li>
<li><a href="http://code.google.com/p/minify/" target="_blank">Google minify</a></li>
</ul>
<p>JSMin &#8211; is a filter which removes comments and unnecessary   whitespace from JavaScript files. It typically reduces filesize by half, resulting in faster downloads.   It also encourages a more expressive programming style because it eliminates   the download cost of clean, literate self-documentation.</p>
<p>Dojo compressor &#8211; in the design of the the Dojo compressor,  instead of brittle regular expressions, the Dojo compressor is based on Rhino, a JavaScript engine from the Mozilla project.</p>
<p>Packer v3.0 &#8211; some features of it are respect Microsoft conditional terms, new option to shrink variable and argument identifiers, removed the special chars feature  (except the <code>;;;</code> feature which people seem to like) etc.</p>
<p>Google minify -  is a PHP5 app that helps you follow several of Yahoo!&#8217;s <a rel="nofollow" href="http://developer.yahoo.com/performance/index.html#rules">Rules for High Performance Web Sites</a>. It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers.</p>
<p style="text-align: left;">YUI compressor &#8211; The YUI Compressor is a JavaScript compressor which, in addition to removing comments and white-spaces, obfuscates local variables using the smallest possible variable name. This obfuscation is safe, even when using constructs such as &#8216;eval&#8217; or &#8216;with&#8217; (although the compression is not optimal is those cases) Compared to JSMin, the average savings is around 20%.</p>
<p style="text-align: left;">Note: it&#8217;s possible to make gzip compression of code, which are supported natively by modern web browsers, and also shrink previously minified JavaScript file.</p>
<h3>Which one to use?</h3>
<p>Well that&#8217;s a personal decision, I read some posts and articles over Internet and most of them suggests YUI compressor, but it don&#8217;t means that you have too.</p>
<p>On web page called <a href="http://compressorrater.thruhere.net/" target="_blank">JavaScript CompressorRater</a> you can found details and analyzes how successful are different compression tools in action. Compression is done on popular JavaScript libraries. I recommend to visit it, at least you can get some view on their success in action.</p>
<h3>Online compress tools</h3>
<p>Here are some online compress tools for beginning:</p>
<ul>
<li><a href="http://www.minifyjs.com/" target="_blank">http://www.minifyjs.com</a></li>
<li><a href="http://jscompress.com/" target="_blank">http://jscompress.com</a></li>
<li><a href="http://javascriptcompressor.com/" target="_blank">http://javascriptcompressor.com</a></li>
</ul>
<p>In some of next posts I&#8217;ll try to explain how to make it done on your computer, not with an online compress tool. Happy compressing!</p>
]]></content:encoded>
			<wfw:commentRss>http://bojanpejic.com/how-to-compress-javascript-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
