Compress JavaScript?

S

Sparhawk

Hi,

the question how to compress JavaScript has been discussed many times
in the news groups but I didn't find a suitable solution.

I need a tool, which
a) does not cost anything
b) removes all white spaces, comments line breaks and so on
c) renames functions and variables to the shortest possible names.
d) converts files statically before making it public (instead of
compressing it in run-time on the server and perhaps inflating it on
the client)

I had a look at jsmin which covers a + b but not c.

Any other tool? I am about to write one myself but would like to safe
me the effort if there was something out there...

Thanks in advance,
Kay
 
J

Jim Ley

Any other tool? I am about to write one myself but would like to safe
me the effort if there was something out there...

Just use gzip, it'll beat anything you can do many times over, and is
infinitely simpler and removes the need of doing QA again after
crunching.

Jim.
 
J

Jim Ley

gzip can't quite cut it in all cases.
For example, some browsers don't do gzip.

Can you name some browsers that can do sensible amounts of javascript
but can't do gzip?

There may be an issue with proxy caches, but then if the proxy cache
is there it's going to be saving the bandwidth anyway, that's what
it's there for, and even this are rare.

With the additional cost of debugging, QA, I really don't think it
makes any sense to do this - that is of course unless you have no
QA...

Jim.
 
S

Sparhawk

Jim,

is the gzip solution standars compliant? I found some examples using the
archive-property of the script-tag, but read that this was not part of
the standard.

Is it supported by all webservers? How's the syntax you would use?

Thanks,
Sparhawk
 
J

Jim Ley

Jim,

is the gzip solution standars compliant?

Yes, absolutely, on most servers you also don't need to do anything
but turn it on.
Is it supported by all webservers?

You turn on mod_gzip on apache, or tick the "gzip" box on IIS, it's
all very simple - you do not change the client in any way at all.

First find out what web-server you have and then we can direct you to
the documentation.

Jim.
 
S

Sparhawk

Jim,

my site (http://www.yucata.de) for which I am looking for a solution is
hosted by a hosting provider. Thus I have no access to the configuration
of the server. But I am sure that it is IIS.

How is the correct syntax for requesting a gzip-Javascript in HTML? I
will just try if it is turned on.

Regards,
Kay
 
J

Jim Ley

How is the correct syntax for requesting a gzip-Javascript in HTML? I
will just try if it is turned on.

It's exactly the same syntax as a non-gzipped one, that's the point of
the solution, it's transparent.

Are you sure it's not already enabled, if it's IIS6.1 there's a good
chance it is.

Jim.
 
S

Steve Neill

Checkout ESC from saltstorm.net. I found 2 bugs in it, but can send
you patches if you choose to use it. We use it all the time and
compresses script to about 50%.

Steve
 
S

Sparhawk

Steve,

yes I will probably use ESC and would love to have your bugfixes before
I run into troubles myself.

If you can't post them you could send them to
(e-mail address removed)
where you would, naturally, remove the _nospam_

Thanks,
Sparhawk
 
J

Jim Ley


Research suggests that's running the Openwave browser which does
support gzip.

(I can't find a UAPROF of the nec e313 though, if you can inspect the
headers it sends it may well send one, then you can look in that RDF
for the: CcppAccept-Encoding globule of RDF.
(at least on mail, it doesn't support gzip)

On mail? well no, that would be difficult there's no http involved to
set the appropriate headers, this is purely an http solution.

Cheers,

Jim.
 
M

Mark Szlazak

Hi,

the question how to compress JavaScript has been discussed many times
in the news groups but I didn't find a suitable solution.

I need a tool, which
a) does not cost anything
b) removes all white spaces, comments line breaks and so on
c) renames functions and variables to the shortest possible names.
d) converts files statically before making it public (instead of
compressing it in run-time on the server and perhaps inflating it on
the client)

I had a look at jsmin which covers a + b but not c.

Any other tool? I am about to write one myself but would like to safe
me the effort if there was something out there...

Thanks in advance,
Kay


Hi Kay,

Here's something I came up with about a year ago. It has your
requirements "a" through "c" but not "d" ... I'm not exactly sure what
d means. Anyway, I hope the comments in the source are enough to help
you understand how it works (or doesn't, there wasn't a lot of QA done
on it). To replace variable names with shorter versions check the
"obfuscate" box.

http://members.aol.com/myscript/jscompress.html

Mark
 
I

Ira Baxter

the question how to compress JavaScript has been discussed many times
in the news groups but I didn't find a suitable solution.

I need a tool, which
a) does not cost anything
b) removes all white spaces, comments line breaks and so on
c) renames functions and variables to the shortest possible names.
d) converts files statically before making it public (instead of
compressing it in run-time on the server and perhaps inflating it on
the client)

Our JavaScript obfuscator does b, c, d. Fails on a :-{
See
http://www.semanticdesigns.com/Products/Obfuscators/ECMAScriptObfucator.html.
 
R

Richard Cornford

Ira Baxter wrote:
Our JavaScript obfuscator does b, c, d. Fails on a :-{

No, it fails on c as well. The shortest possible legal javascript
identifier is only one character long.

Richard.
 
I

Ira Baxter

Richard Cornford said:
Ira Baxter wrote:



No, it fails on c as well. The shortest possible legal javascript
identifier is only one character long.

Richard.

I think by any reasonable interpretation it does just fine on c.
The examples on our web pages show that most non-public variable names
are in fact renamed to single characters. If you wanted to split hairs,
it does not choose the shortest possible name under every circumstance,
as it does not account for the possibility that different scopes can
have different names, nor does it incorrectly rename public names.
Other than that, it does a very good job of minimizing name length.

-- IDB
 
R

Ryan Agler

Steve,

Could you also send me the ESC patches? Please send to
(e-mail address removed) (take out the _nospam_)

Thank you!!!
 
J

Julian Turner

Hello,

I am new to this group.

I wrote (a couple of years ago now) an obfuscator written totally in
Javascript which you can try at http://www.baconbutty.com, look under
Web Development -> My Projects.

It fails under (c) however, for no reason other than that I was
concentrating more on obfuscation than compression. I would just need
to fiddle around with the settings for variable length.

Hope it is of some interest.

Julian Turner
 

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

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top