<?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>Ankur&#039;s PHP and Javascript blog &#187; Javascript</title>
	<atom:link href="http://www.ankur.com/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ankur.com/blog</link>
	<description>PHP and javascript blog</description>
	<lastBuildDate>Tue, 10 Nov 2009 14:28:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript and CSS compression using YUI compressor, PHP and gzip</title>
		<link>http://www.ankur.com/blog/83/php/javascript-css-compression-yui-compressor-php-gzip/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=javascript-css-compression-yui-compressor-php-gzip</link>
		<comments>http://www.ankur.com/blog/83/php/javascript-css-compression-yui-compressor-php-gzip/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 11:47:46 +0000</pubDate>
		<dc:creator>Ankur Motreja</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[YUI compressor]]></category>

		<guid isPermaLink="false">http://www.ankur.com/blog/?p=83</guid>
		<description><![CDATA[It is well known that visitors to your site will not wait for a long time for your page to load. This post will show you how to optimize your pages by reducing the number and size of javascript and CSS files.

Compressing javascript and CSS
The YUI Compressor allows you to easily reduce the size of [...]


Related posts:<ol><li><a href='http://www.ankur.com/blog/106/php/resume-http-downloads-php-curl-fsockopen/' rel='bookmark' title='Permanent Link: Resume HTTP downloads in PHP using cURL or fsockopen'>Resume HTTP downloads in PHP using cURL or fsockopen</a></li><li><a href='http://www.ankur.com/blog/68/php/curl-wrapper-class-cli-php-extension-support/' rel='bookmark' title='Permanent Link: cURL wrapper class with executable and PHP extension support'>cURL wrapper class with executable and PHP extension support</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>It is well known that visitors to your site will not wait for a long time for your page to load. This post will show you how to optimize your pages by reducing the number and size of javascript and CSS files.</p>
<p><span id="more-83"></span></p>
<h3>Compressing javascript and CSS</h3>
<p>The <a rel="nofollow" href="http://developer.yahoo.com/yui/compressor/"rel="nofollow"  target="_blank">YUI Compressor</a> allows you to easily reduce the size of javascript and CSS files by removing comments, extra white spaces, reducing the length of variables where applicable, etc from them. The result is a smaller sized file which works exactly like the original.</p>
<p>Compressing using the YUI Compressor is quite straight forward:</p>
<pre class="brush: bash;">
java -jar &quot;yuicompressor-2.4.2.jar&quot; --type js -o &quot;file.compress.js&quot; &quot;file.js&quot;
java -jar &quot;yuicompressor-2.4.2.jar&quot; --type css -o &quot;file.compress.css&quot; &quot;file.css&quot;
</pre>
<p>Here, file.compress.js and file.compress.css are the compressed output files and file.js and file.css are the input files. These compressed files will work exactly like the original ones. So, you can simple replace the originals with these new compressed files and immediately start seeing faster page load times.</p>
<h3>Combining multiple files into one file</h3>
<p>We have reduced the file sizes in the previous step. However, we might still have multiple javascript and CSS files required to completely load the page. This means the page has to make one HTTP request for each file it requires. Why not combine all the javascript files into one single .js file and all the CSS files into one single .css file ?</p>
<p>You can use any text editor and simple copy paste the contents into one javascript and CSS file. You will then need to modify your page to include these files instead of multiple javascript and CSS files.</p>
<p>Please note that this technique of combining files can end up requiring the user to download a large .js and .css file for each page if each page requires a different set of files. In that case, you might want to use this technique for only the core files that are required on each page or most pages.</p>
<h3>Serve gziped files via PHP</h3>
<p>Now that we have reduced the size and number of files considerably, we can further reduce the size by serving gzip content. If you use mod_gzip on apache, you might already be serving gziped files. However, you might still wish to use this section as compressing content on the fly with gzip might be slower than this technique.</p>
<p>We will first need to gzip the contents of the combined file from the previous step. Lets assume the file was file.js and the gzip compressed file is file.js.gz.</p>
<p>This file needs to be served through a PHP file. You can use the PHP code below to serve this file.</p>
<pre class="brush: php;">
$longExpiryOffset = 315360000;
header ( &quot;Cache-Control: public, max-age=&quot; . $longExpiryOffset );
header ( &quot;Expires: &quot; . gmdate ( &quot;D, d M Y H:i:s&quot;, time () + $longExpiryOffset ) . &quot; GMT&quot; );

header ( &quot;Content-type: text/javascript; charset=utf-8&quot; );

//Check if browser can handle gzip content
if (stripos ( $HTTP_SERVER_VARS [&quot;HTTP_ACCEPT_ENCODING&quot;], &quot;gzip&quot; ) === false) {
 readfile(&quot;file.js&quot;);
} else {
 header(&quot;Content-Encoding: gzip&quot;);
 readfile(&quot;file.js.gz&quot;);
}
</pre>
<p>Similarly, to serve CSS, replace text/javascript with text/css in line 5 and change the file names.</p>
<p>Of course, you will have to modify the HTML in your page to load this PHP script instead of the javascript and css files.</p>
<p>These steps should improve the page load time of your page considerably.</p>


<p>Related posts:<ol><li><a href='http://www.ankur.com/blog/106/php/resume-http-downloads-php-curl-fsockopen/' rel='bookmark' title='Permanent Link: Resume HTTP downloads in PHP using cURL or fsockopen'>Resume HTTP downloads in PHP using cURL or fsockopen</a></li><li><a href='http://www.ankur.com/blog/68/php/curl-wrapper-class-cli-php-extension-support/' rel='bookmark' title='Permanent Link: cURL wrapper class with executable and PHP extension support'>cURL wrapper class with executable and PHP extension support</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ankur.com/blog/83/php/javascript-css-compression-yui-compressor-php-gzip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazing Tree javascript library</title>
		<link>http://www.ankur.com/blog/63/javascript/amazing-tree-javascript-library/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=amazing-tree-javascript-library</link>
		<comments>http://www.ankur.com/blog/63/javascript/amazing-tree-javascript-library/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 09:18:50 +0000</pubDate>
		<dc:creator>Ankur Motreja</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Amazing Tree]]></category>

		<guid isPermaLink="false">http://www.ankur.com/blog/?p=63</guid>
		<description><![CDATA[Some time back, I required a drag and drop tree implemented in javascript where you could rearrange nodes by dragging them around the tree. I decided to make a post and release it. Its called Amazing Tree. The code is available for download from the projects page.
A few demos of the library in action:
Scroll Demo
Full [...]


Related posts:<ol><li><a href='http://www.ankur.com/blog/30/javascript/frame-glider-javascript-library/' rel='bookmark' title='Permanent Link: Frame Glider javascript library'>Frame Glider javascript library</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Some time back, I required a drag and drop tree implemented in javascript where you could rearrange nodes by dragging them around the tree. I decided to make a post and release it. Its called <a href="http://www.ankur.com/blog/amazing-tree/">Amazing Tree</a>. The code is available for download from the <a href="http://www.ankur.com/projects.php#AmazingTree" rel="nofollow" >projects</a> page.</p>
<p><span id="more-63"></span>A few demos of the library in action:</p>
<p><a href="http://www.ankur.com/projects/AmazingTree/demo/demo1.html" rel="nofollow"  target="_blank">Scroll Demo</a></p>
<p><a href="http://www.ankur.com/projects/AmazingTree/demo/demo2.html" rel="nofollow"  target="_blank">Full Demo</a></p>
<p><a href="http://www.ankur.com/projects/AmazingTree/demo/demo3.html" rel="nofollow"  target="_blank">Cone Demo</a></p>
<p>You will find more information and detailed documentation at the <a href="http://www.ankur.com/blog/amazing-tree/">Amazing Tree page</a></p>


<p>Related posts:<ol><li><a href='http://www.ankur.com/blog/30/javascript/frame-glider-javascript-library/' rel='bookmark' title='Permanent Link: Frame Glider javascript library'>Frame Glider javascript library</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ankur.com/blog/63/javascript/amazing-tree-javascript-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frame Glider javascript library</title>
		<link>http://www.ankur.com/blog/30/javascript/frame-glider-javascript-library/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=frame-glider-javascript-library</link>
		<comments>http://www.ankur.com/blog/30/javascript/frame-glider-javascript-library/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 10:14:12 +0000</pubDate>
		<dc:creator>Ankur Motreja</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Frame Glider]]></category>

		<guid isPermaLink="false">http://www.ankur.com/blog/?p=30</guid>
		<description><![CDATA[I had written a javascript library Frame Glider some time back which allows you to drag and drop page elements across frames or iframes within a browser window. The code is now available for download from the projects page.

Some demos are available too:
Simple Demo
Complex Demo
Frame as a droppable
More details including detailed documentation are available at [...]


Related posts:<ol><li><a href='http://www.ankur.com/blog/63/javascript/amazing-tree-javascript-library/' rel='bookmark' title='Permanent Link: Amazing Tree javascript library'>Amazing Tree javascript library</a></li><li><a href='http://www.ankur.com/blog/83/php/javascript-css-compression-yui-compressor-php-gzip/' rel='bookmark' title='Permanent Link: Javascript and CSS compression using YUI compressor, PHP and gzip'>Javascript and CSS compression using YUI compressor, PHP and gzip</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I had written a javascript library <a href="http://www.ankur.com/blog/frame-glider/" target="_self">Frame Glider</a> some time back which allows you to drag and drop page elements across frames or iframes within a browser window. The code is now available for download from the <a href="http://www.ankur.com/projects.php#FrameGlider" rel="nofollow"  target="_self">projects</a> page.</p>
<p><span id="more-30"></span></p>
<p>Some demos are available too:</p>
<p><a rel="nofollow" href="../../projects/FrameGlider/demo/simple/a.html" rel="nofollow"  target="_blank">Simple Demo</a></p>
<p><a rel="nofollow" href="../../projects/FrameGlider/demo/complex/a.html" rel="nofollow"  target="_blank">Complex Demo</a></p>
<p><a rel="nofollow" href="../../projects/FrameGlider/demo/frame_drop/a.html" rel="nofollow"  target="_blank">Frame as a droppable</a></p>
<p>More details including detailed documentation are available at the <a href="http://www.ankur.com/blog/frame-glider/" target="_self">Frame Glider page</a></p>


<p>Related posts:<ol><li><a href='http://www.ankur.com/blog/63/javascript/amazing-tree-javascript-library/' rel='bookmark' title='Permanent Link: Amazing Tree javascript library'>Amazing Tree javascript library</a></li><li><a href='http://www.ankur.com/blog/83/php/javascript-css-compression-yui-compressor-php-gzip/' rel='bookmark' title='Permanent Link: Javascript and CSS compression using YUI compressor, PHP and gzip'>Javascript and CSS compression using YUI compressor, PHP and gzip</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ankur.com/blog/30/javascript/frame-glider-javascript-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
