Improving Performance by Combining Scripts and CSS

According to the Yahoo! performance team, the best way to improve your web site’s performance is to reduce the number of requests for assets such as scripts, style sheets and images. One way to accomplish this is by combining all the script files into one and serving only that file in your production environment. The same approach can also be applied to cascading style sheets.

The guys at Cozi have created a server side solution that takes the pain out of combining these files in some sort of intermediary build process. Here is how they go about doing it:

<WebClientCode:CombinerControl ID=”CombineScript” runat=”server”>

<script src=”script/third-party/jquery.js” type=”text/javascript”></script>

<script src=”script/third-party/sifr.js” type=”text/javascript”></script>

<script src=”script/third-party/soundmanager.js” type=”text/javascript”></script>

<script src=”script/cozi_date.js” type=”text/javascript”></script>

</WebClientCode:CombinerControl>

The combiner outputs a reference to an Http Handler which will serve the combined file:

<script src=“../Combiner/Combiner.ashx?ext=js ?
&ver=59169b00 ?
&type=text%2fjavascript ?
&files=!script’third-party*jquery*sifr*soundmanager*!script*cozi_date*” ?
type=”text/javascript”></script>

Although they do not provide the source code for the ASP.NET control, they do point to an old article on Vitamin, Serving JavaScript Fast, that served as their inspiration.

Personally I prefer combining the files before they get pushed to production in a build process, as doing it while the client may introduce unexpected delays depending on the traffic load a any given time.

What do you do to improve performance on your web sites?

Claude is as a solutions architect at a unified communications company. He also helps small businesses increase their productivity, improve back-office processes and reduce costs by promoting the use of new technologies.
This entry was posted in How-To and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>