faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

31 of 53 people (58%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

Can I compress .js files and load them from an archive file?
Can I put my .js files into a .zip archive?

Aug 12th, 2002 14:52
John Repici, Thomas Loo, Chris Morris, Martin Honnen,


Actually, this doesn't work at all, if you read the documentation 
linked above, you will findout that the archive tag is used for signing 
scripts, if you used the HTML above it would work for IE, but onlu 
because it would ignore the archive tag, then load the js un-compressed.

As far as i can see, this is not possible, you cannot compress js files.

---
HOWEVER: You may find this helpful - http://www.creativyst.com/Prod/3/

It is a cross platform way to squeeze down your js files WITHOUT plug-
ins or self-extracting overhead.  Typically you get about 40% 
reductions, even more if you comment your code a lot.
   -jr
---
Netscape 4.x can handle ZIP compressed javascript. Since a common java-
thing is to bundle classes, images etc into a single JAR archive, I did 
some testing and found out that this actually works with javascript 
aswell.
 This is achieved by combining the ARCHIVE and SRC attribute in a 
SCRIPT tag, as follows;

<SCRIPT
  LANGUAGE="Javascript1.2" 
  ARCHIVE="/path/to/myscript.zip" 
  SRC="myscript.js">
</SCRIPT>

...now, find yerself a decent shell-version of ZIP
(Win32 Users: ftp://ftp.freesoftware.com/pub/infozip/WIN32/zip23xN.zip)
and build a zip-archive including myscript.js with the following 
command:
 zip.exe -9 -o -j -D myscript myscript.js

- NOTE! -
* I have not tried including multiple scripts into an archive,
  don't see why it shouldn't work though...
* You may need to access the archive over http to supply NN with
  correct content-type header.
* ZIP compression will ONLY work with NN4.x, if you intend to serve
  crossbrowser compressed scripts you'll have to prepare a gzip version
  aswell. gzipped scripts over the http-protocol do fine on
  MSIE4+(Win32, UNIX?) and NN6(M17+).
---