Javascript file compactor wanted

A

Aaron Gray

Hi,

Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.

Many thanks in advance,

Aaron
 
P

pcx99

Aaron said:
Hi,

Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.

Many thanks in advance,

Aaron


If you have access to your .htaccess file on your web server then you
can use some rewrite rules to send external javascript files as
compressed gzip files. The browser will send a header if it can accept
gzip compression (most every browser can), if it can just pass it the
script.js.gz file and if it can't have the rewrite engine pass the
script.js file.

You'll not get better throughput any other way (and you can leave your
js files mostly readable since you don't have to strip whitespace).
 
P

Peter Michaux

pcx99 said:
If you have access to your .htaccess file on your web server then you
can use some rewrite rules to send external javascript files as
compressed gzip files. The browser will send a header if it can accept
gzip compression (most every browser can), if it can just pass it the
script.js.gz file and if it can't have the rewrite engine pass the
script.js file.

You'll not get better throughput any other way (and you can leave your
js files mostly readable since you don't have to strip whitespace).

To get the best results use both minimization and compression together.
The reason both are useful is there is no need to compress and send the
comments or whitespace.

<URL: http://yuiblog.com/blog/2006/10/16/pageweight-yui0114/>

It also helps to reduce the number of JavaScript files by concatenating
them together

<URL: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/>

Peter
 
P

pcx99

Peter said:
To get the best results use both minimization and compression together.
The reason both are useful is there is no need to compress and send the
comments or whitespace.

<URL: http://yuiblog.com/blog/2006/10/16/pageweight-yui0114/>

It also helps to reduce the number of JavaScript files by concatenating
them together

<URL: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/>

Peter

I just fooled around with the rewrite engine and took my 10k common JS
file and created a gz version (didn't even tweak the settings) and it's
now a 3k file. The rewrite engine puts a performance hit on the server
but that is MORE than overcome by the bandwidth (and to a far lesser
extent) storage space savings. It won't work for php files but for any
static html or ANY static file be it .js, .css, etc it will work
invisibly and transparently. Just drop a gz copy of the file alongside
the original and if the browser can handle it the server will send the
compressed file...

RewriteEngine on
RewriteOptions Inherit

#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} (gzip.*)

#make sure there's no trailing .gz on the url
#ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$

#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f

#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [L]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top