Friday, January 23, 2009

Minification of javascript has many benefits. One thing that is a pain for developers is remembering to pack your javascript before deployment. Another big pain is if you need to do an on-server change of some JavaScript code. Using Packer JavaScript en PHP a small PHP file and a tweak to .htaccess you can minify your JavaScript on the fly and never again have to worry about minifying your javascript.



First, download the Packer JavaScript en PHP and extract class.JavaScriptPacker.php to some location on your server.



Now create a .PHP file with the following code.




Next, bust open the .htaccess and add the following. Note you should have mod_rewrite enabled and mod_rewrite set to ON. If you dont know how to do this, contact your sysadmin or check it out on apache's website.




Now, the concept here is pretty simple. You take any .js javascript file and route it through the proxy. Once the proxy gets it, the packer compresses it.



Need to exclude a file? Simply make it .jsx or some other extension other than .js, the browser doesn't care but mod_rewrite will ignore it.
Comments:
What would be the Mod_rewrite rule to reverse the js rule that you could apply to a htaccess file in other folder?
 
Reverse it? You mean not compress it? The easiest way to handle this is to change .htaccess to look for .jsx instead of .js and then you can selectively compress instead of selectively exclude.
 
Post a Comment

Links to this post:

Create a Link

<< Home


Recent Posts


Super Simple AJAX Forms with jQuery and JSON : dat...
Super Simple AJAX Forms with jQuery and JSON : web...
Super Simple AJAX Forms with jQuery and JSON : Int...
Print Buttons Anywhere
Icons after your links
Changes in web hosting
Web Table Sorting (Without the headache)
Google Chart API
1PB Storage, $17,8800 Not bad eh?
Google Chrome Anyone?


Archives

01/01/2005 - 02/01/2005
02/01/2006 - 03/01/2006
03/01/2006 - 04/01/2006
04/01/2006 - 05/01/2006
05/01/2006 - 06/01/2006
09/01/2006 - 10/01/2006
10/01/2006 - 11/01/2006
11/01/2006 - 12/01/2006
12/01/2006 - 01/01/2007
04/01/2007 - 05/01/2007
05/01/2007 - 06/01/2007
01/01/2008 - 02/01/2008
02/01/2008 - 03/01/2008
05/01/2008 - 06/01/2008
06/01/2008 - 07/01/2008
08/01/2008 - 09/01/2008
09/01/2008 - 10/01/2008
11/01/2008 - 12/01/2008
12/01/2008 - 01/01/2009
01/01/2009 - 02/01/2009
02/01/2009 - 03/01/2009
04/01/2009 - 05/01/2009
05/01/2009 - 06/01/2009
07/01/2009 - 08/01/2009
01/01/2010 - 02/01/2010

My Software

Blinky - GBPVR Plugin
PhotoCopy - GBPVR Plugin
QTC - Quick Test Case
rBoop - Rob's Timers

Programming Links

C# Formatter
NSIS

Other Links

Damn Small Linux

Sites I Manage

Do it yourself SEO. Cheap.
Pet Supplies
Dog toy of the month club
SqueakerZ pet Deals
Geocaching Community
Hitch hiker Tracking