HomeBlogProjects

Other Projects


JSZip and CSZip

  • Description/Demo
  • Docs/Download
  • Discuss/Debug
Two PHP programs for merging js and css files together and outputting them minified, zipped, and cached. Option to pack them as well. The files were originally written by me for the backend of the download manager for JQuery UI 1.0, and I've adapted them for more general use, and upgraded them to PHP5.
When a web page is requested, usually only two requests are delivered at a time, so if there are a lot of scripts and stylesheets, this can result in a significant delay in rendering a web page. By using these programs, only one file is delivered for each type, and by outputting them minified and zipped, bandwidth is significantly reduced along with total bytes served, which is important nowadays when ISPs are charging once a website goes over a given limit.
Unless set otherwise, minifying, which uses the excellent JSMin.php by Ryan Grove, is a one off event as the individual files get saved to the server. This way on subsequent requests the minified files are just merged and zipped, so visitors get the files fast.

The files can be downloaded from here
The zipped file includes JSMin.php and class.JavascriptPacker.php, so it can be up and running straight away.
To use them you just set the script and style tags so:
<script type="text/javascript" src="path/jszip.php?files=jquery1.2.6,jqtreetable,other,files">
</script>
or
<link href="path/cszip.php?files=list,of,css,files" rel="stylesheet" type="text/css" />

Doing it this way makes it easy to serve different scripts and stylesheets for different pages without having to worry about conflicts. Also, if you change a script or stylesheet, you just need to give it a different name, and change the url using the new name, and visitors will get a single file with the changed file in it.

You don't need to use the js or css extensions in the urls, as the programs will add those as required.
In the jszip file, you just need to specify where your scripts are stored and where you want the minified files stored.
In the cszip file, you need to specify the location of the css files, and the location of any images you use in the css url directives, both relative to where cszip.php is stored. This way, if you use image urls for things like backgrounds, you don't have to edit the new path by hand. The cszip file will set these.
If I've missed anything, please leave a comment.

1 Comment

Post New Comment
Submitted by John James on Fri 17 Apr 2009 3:16
Hi there,
Just to say I found these very useluf and simple to set up. Thanx.
Add comments here
Name:
Email:
URL:
Comment:BoldItalicUnderlineCreate linkCode BlockInsert Unordered List

JQuery/PHP Website and Applications Developer, based in Ireland.
Interests: Open Source Software, Supercomputers, Financial Markets, Sport, Science, Sustainable Energy. AGW Skeptic.

follow paulhan on twitter
Help me build a supercomputer