<?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>Anand Nalya &#187; optimization</title>
	<atom:link href="http://anandnalya.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://anandnalya.com</link>
	<description>blog</description>
	<lastBuildDate>Wed, 04 Jan 2012 06:55:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Minifying Javascript/css without changing file references in your source</title>
		<link>http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=minifying-javascriptcss-without-changing-file-references-in-your-source</link>
		<comments>http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 13:21:02 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[compressor]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=79</guid>
		<description><![CDATA[Rule 10 of Steve Souders High Performance Web Sites: Minify Javascript The most common problem faced while implemnting this is how you handle the full and minified version and how to change there reference in referencing documents. One of the &#8230; <a href="http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Rule 10 of Steve Souders High Performance Web Sites: <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_8.html">Minify Javascript</a></p>
<p>The most common problem faced while implemnting this is how you handle the full and minified version and how to change there reference in referencing documents. One of the easier ways to do this is to make it part of the deployment process. </p>
<p>Here are the relevent steps involved.</p>
<p>I&#8217;m using <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>.<br />
<div id="gist-1124427" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c">#!/bin/bash</span></div><div class='line' id='LC2'>&nbsp;</div><div class='line' id='LC3'><span class="c">#Execute this script after checking out the latest source from repository.</span></div><div class='line' id='LC4'>&nbsp;</div><div class='line' id='LC5'><span class="c">#Minify all javascript files</span></div><div class='line' id='LC6'><span class="nb">cd</span> /path/to/javascript</div><div class='line' id='LC7'><span class="k">for </span>x in <span class="sb">`</span>ls *.js<span class="sb">`</span></div><div class='line' id='LC8'><span class="k">do</span></div><div class='line' id='LC9'><span class="k">        </span>java -jar /path/to/compressor/yuicompressor-2.4.2.jar -o <span class="k">${</span><span class="nv">x</span><span class="p">%%.*</span><span class="k">}</span>-min.js --preserve-semi  <span class="nv">$x</span></div><div class='line' id='LC10'><span class="k">done</span></div><div class='line' id='LC11'>&nbsp;</div><div class='line' id='LC12'><span class="c">#Minfiy all css files</span></div><div class='line' id='LC13'><span class="nb">cd</span> /path/to/css</div><div class='line' id='LC14'><span class="k">for </span>x in <span class="sb">`</span>ls *.css<span class="sb">`</span></div><div class='line' id='LC15'><span class="k">do</span></div><div class='line' id='LC16'><span class="k">        </span>java -jar /path/to/compressor/yuicompressor-2.4.2.jar -o <span class="k">${</span><span class="nv">x</span><span class="p">%%.*</span><span class="k">}</span>-min.css  <span class="nv">$x</span></div><div class='line' id='LC17'><span class="k">done</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1124427/ad846053c02470535698614eed39c9401f5caa88/minify.sh" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1124427#file_minify.sh" style="float:right;margin-right:10px;color:#666">minify.sh</a>
            <a href="https://gist.github.com/1124427">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
<br />
Now you don&#8217;t want to replace all references to <em>x.css</em> or <em>x.js</em> in your development code with references to <em>x-min.css</em> and <em>x-min.js</em> respectively. So what you can do is rewrite all those filenames at the web server level.</p>
<p>For apache the following rewrite rules work fine:<br />
<div id="gist-1124427" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>#enable rewriting</div><div class='line' id='LC2'>RewriteEngine on</div><div class='line' id='LC3'>RewriteRule /(.*)\.js /$1-min.js</div><div class='line' id='LC4'>RewriteRule /(.*)\.css /$1-min.css</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1124427/0a7c12d3f31f779d173b821962361c0d2f176f65/httpd.conf" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1124427#file_httpd.conf" style="float:right;margin-right:10px;color:#666">httpd.conf</a>
            <a href="https://gist.github.com/1124427">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
<br />
<em>Caution:</em> Remember to delete existing minified css/js file before running the minifying script or you will end up with file names like x-min-min-min.js and so on. One way to do this is to clear the js/css folder before checking out files from your source repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

