Friday, July 04, 2008

Easily combine and compress (minify) JavaScript and CSS in Coldfusion

Introducing Combine.cfc. A project designed to speed up your website!

The problem

Adding lots of JavaScript and CSS to your website can have a detrimental effect on its performance.

Combine.cfc is an open source project I have released to help address this problem.

The solution

Combine.cfc can compress (minify) multiple JavaScript or CSS files into single requests.

Change this:

<script src='file1.js' type='text/javascript'></script>
<script src='file2.js' type='text/javascript'></script>

To this:

<script src='combine.cfm?files=file1.js,file2.js' type='text/javascript'></script>

Why?

  1. The CSS and JavaScript content is minified, removing redundancy (comments, white space, etc). This keeps the bandwidth to a minimum.
  2. You reduce the overhead of excessive HTTP requests.
  3. You can be as liberal as you like with your comments and white space, it will all be stripped from the final output.
  4. You can continue to separate your code into individual files, for ease of maintenance/development/version control and general developer well-being and sanity!

For more information, and to download the code, visit the Combine.cfc project page.

0 comments:

 
Copyright Magnolia Box