473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Compress JavaScript?

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
Jul 23 '05 #1
24 2534
Sparhawk wrote:
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...


The time required to write such a tool would have been enormeous.

I dont know workings of mr Douglas Crockford's jsmin, havent read this
NG quite some years, but more than 3 years ago the best one on the
js-scene was mr Thomas Loo's "ESC"

http://www.saltstorm.net/depo/esc/crunching.wbm

which outweighed mr Mike Hall's works "JavaScript Crunchinator"
http://www.brainjar.com/js/crunch/
which was probably the best one available prior ESC came out.

hope I saved you a lot of time

--
marekmand
Talliinn, Estonia
Jul 23 '05 #2
On 24 Oct 2004 13:41:17 -0700, Ka************@gmx.de (Sparhawk) wrote:
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.
Jul 23 '05 #3
Jim Ley <ji*@jibbering.com> wrote:
On 24 Oct 2004 13:41:17 -0700, Ka************@gmx.de (Sparhawk) wrote:
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.


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

Jul 23 '05 #4
Marek M?nd <ca********@mail.ee> wrote:
Sparhawk wrote:
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...
The time required to write such a tool would have been enormeous.

Not really.
An hour or two.

B is trivial.
I wrote one in about 3 minutes.
C is a bit harder, and would require a minimal parser, and list of
reserved words.
D (compress reserved words by replacing with calls to them using shorter
names) is a bit harder yet.

I dont know workings of mr Douglas Crockford's jsmin, havent read this
NG quite some years, but more than 3 years ago the best one on the
js-scene was mr Thomas Loo's "ESC"

http://www.saltstorm.net/depo/esc/crunching.wbm

which outweighed mr Mike Hall's works "JavaScript Crunchinator"
http://www.brainjar.com/js/crunch/
which was probably the best one available prior ESC came out.

hope I saved you a lot of time

Jul 23 '05 #5
On 25 Oct 2004 12:29:49 GMT, Ian Stirling <ro**@mauve.demon.co.uk>
wrote:
Jim Ley <ji*@jibbering.com> wrote:
On 24 Oct 2004 13:41:17 -0700, Ka************@gmx.de (Sparhawk) wrote:
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.


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.
Jul 23 '05 #6
Thanks,

the ESC thing is exactly what I have been looking for!

It's still a shame that I found a tool, I always wanted to program a
parser myself and started yesterday :))

Anyway, thanks,
Sparhawk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
On 25 Oct 2004 15:57:49 GMT, Sparhawk <no****@devdex.com> wrote:
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.
Jul 23 '05 #9
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #10
On 26 Oct 2004 07:27:49 GMT, Sparhawk <no****@devdex.com> wrote:
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.
Jul 23 '05 #11
Jim Ley <ji*@jibbering.com> wrote:
On 25 Oct 2004 12:29:49 GMT, Ian Stirling <ro**@mauve.demon.co.uk>
wrote:
Jim Ley <ji*@jibbering.com> wrote:
On 24 Oct 2004 13:41:17 -0700, Ka************@gmx.de (Sparhawk) wrote:

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.


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?


The one on my mobile.
It does javascript, not gzip.

Jul 23 '05 #12
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
Jul 23 '05 #13
On 26 Oct 2004 18:47:35 GMT, Ian Stirling <ro**@mauve.demon.co.uk>
wrote:
Jim Ley <ji*@jibbering.com> wrote:
Can you name some browsers that can do sensible amounts of javascript
but can't do gzip?


The one on my mobile.
It does javascript, not gzip.


Which UA? (which mobile if it's the default one on the pone)

Jim.
Jul 23 '05 #14
Steve Neill wrote:
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%.


If its buggy, then why dont you contact the author of it, so he will be
notified about the bugs? Would be a proper thing to do...

Or has he lost all the interest in it? Dont know.
Jul 23 '05 #15
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
ka********************@gmx.de
where you would, naturally, remove the _nospam_

Thanks,
Sparhawk

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #16
Jim Ley <ji*@jibbering.com> wrote:
On 26 Oct 2004 18:47:35 GMT, Ian Stirling <ro**@mauve.demon.co.uk>
wrote:
Jim Ley <ji*@jibbering.com> wrote:
Can you name some browsers that can do sensible amounts of javascript
but can't do gzip?


The one on my mobile.
It does javascript, not gzip.


Which UA? (which mobile if it's the default one on the pone)


NEC e313 (at least on mail, it doesn't support gzip)
Jul 23 '05 #17
On 28 Oct 2004 11:45:47 GMT, Ian Stirling <ro**@mauve.demon.co.uk>
wrote:
Jim Ley <ji*@jibbering.com> wrote:
On 26 Oct 2004 18:47:35 GMT, Ian Stirling <ro**@mauve.demon.co.uk>
wrote:
Jim Ley <ji*@jibbering.com> wrote:
Can you name some browsers that can do sensible amounts of javascript
but can't do gzip?

The one on my mobile.
It does javascript, not gzip.
Which UA? (which mobile if it's the default one on the pone)


NEC e313


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.
Jul 23 '05 #18
Ka************@gmx.de (Sparhawk) wrote in message news:<74**************************@posting.google. com>...
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
Jul 23 '05 #19

"Sparhawk" <Ka************@gmx.de> wrote in message
news:74**************************@posting.google.c om...

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/Produ...Obfucator.html.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Jul 23 '05 #20
Ira Baxter wrote:
Sparhawk wrote:
I need a tool, which <snip> c) renames functions and variables to the shortest possible
names.
<snip>
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.
Jul 23 '05 #21
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:cm*******************@news.demon.co.uk...
Ira Baxter wrote:
Sparhawk wrote:
I need a tool, which <snip> c) renames functions and variables to the shortest possible
names.

<snip>
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 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
Jul 23 '05 #22
Steve,

Could you also send me the ESC patches? Please send to
ry***************@hotmail.com (take out the _nospam_)

Thank you!!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #23
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
Jul 23 '05 #24
It turns out that gzipping external script references doesn't always
work properly on IE, if the script is cached on the client. I've
posted a wacky but functional workaround for this problem at
http://jgwebber.blogspot.com/2004/12...mpression.html.
It's not entirely simple, but it does have the nice property of
working on both IE and Mozilla.

Hope this helps,
joel.

Jul 23 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tony | last post by:
Hello, Any assistance would be appreciated: As the subject suggests I am trying to gunzip files using the Compress::Zlib module. The following is basically the code that I am working with: ...
11
by: Shiperton Henethe | last post by:
Dreamweaver 4 Hi Can anyone recommend a decent utility for compressing HTML that is safe - i.e. that *definitely* doesn't mess with the appearance in any browsers. I run a growing website...
5
by: Alan | last post by:
I have a website with no ssi, php, cgi...nothing. Plain old flat pages are all it serves. I need to upload a list to it - a big, plain text list in html. A 2Mb list! With gzip compress, it comes...
1
by: Barkster | last post by:
Are there any resources in the form of tutorials or anything that show how to do client side image resizing before uploading. I'm using thinimage and works great but I'm just interested in seeing...
3
by: dust | last post by:
I need to improve the download speed for an asp.net 2.0 application. So I'd like to compress the dimension of the .aspx pages. These pages don't have any images or heavy element. The most long...
6
by: Champika Nirosh | last post by:
Hi, I have two machine where I needed to have a extended TCP/IP protocol to make the link between the two machines Mean,I need to write a application that compress every data the machine send...
3
by: kpmassey | last post by:
I'm using javascript to construct large tables from an array of data, using ideas from: http://www.oreillynet.com/pub/a/javascript/2003/05/06/dannygoodman.html The data itself cannot be...
11
by: Ciaran | last post by:
HI I know about ob_start( 'ob_gzhandler' ); But I'm looking for something that removes all line breaks and extra whitespace in the html before sending it to the visitor's browser. Is this...
5
by: zgh1970 | last post by:
Hi, Friends, default DB2 compression library. I am wondering if this option will have any new restriction on RESTORE in the following. (Can I used that backup imsage for restore at the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.