Robs Programming Junk
Welcome to my programming blog!With some luck you will find some tasty nuggets of information here. If you do find something please post a comment on where or how you used it. I like to see what sort of impact my work has on others.
Friday, January 23, 2009
On the fly JavaScript Packing - Speed up your site!
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.
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:
Links to this post: << Home
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: << Home
View my portfolio at iFreelance.com
Hire MechSoftware for Quality Assurance (QA), Database Programming, and Security Design/Programming
Find QA Freelance Jobs at iFreelance.com
Hire MechSoftware for Quality Assurance (QA), Database Programming, and Security Design/Programming
Find QA Freelance Jobs at iFreelance.com
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/200502/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 PluginPhotoCopy - GBPVR Plugin
QTC - Quick Test Case
rBoop - Rob's Timers
Programming Links
C# FormatterNSIS
Other Links
Damn Small LinuxSites I Manage
Do it yourself SEO. Cheap.Pet Supplies
Dog toy of the month club
SqueakerZ pet Deals
Geocaching Community
Hitch hiker Tracking

