422,904 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,904 IT Pros & Developers. It's quick & easy.

Javascript file compactor wanted

P: n/a
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
Jan 6 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a

Aaron Gray wrote:
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.
<URL: http://www.crockford.com/javascript/jsmin.html>

Jan 6 '07 #2

P: n/a
Aaron Gray wrote:
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).

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 6 '07 #3

P: n/a
pcx99 wrote:
Aaron Gray wrote:
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).
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

Jan 6 '07 #4

P: n/a
Peter Michaux wrote:
pcx99 wrote:
>Aaron Gray wrote:
>>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).

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]
--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 6 '07 #5

P: n/a
Rik
pcx99 wrote:
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.
The output of a php file can also easily be gzipped, by using either
ob_gzhandler() or zlib.output_compression. Zipping the source is somewhat
useless as it doesn't get send anyway.
--
Rik Wasmus
Jan 6 '07 #6

P: n/a
Thanks Guys I will check these options out.

Many thanks,

Aaron
Jan 6 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.