dean.edwards.name/weblog/2005/06/packer201/

packer 2.0.1

The last of today’s updates, packer 2.0.1 is a bug fix release. The bug was in the interface (not the algorithm) and affected Opera (badly) and Mozilla (when using high ASCII encoding).

There is another conversion of packer in the works. Rob Seiler is working on a version written in perl. I look forward.:-)

I’m seeing a lot more JavaScript compressors come out of the woodwork lately. As we enter an era of AJAX and DOM scripting, script libraries are getting bigger and adding to the overall weight of a page. It is worth noting that packer was the first script I wrote before publishing this site. I’m not sure how many users IE7 would have if it was issued as a 90K script. After compression it weighs in at a modest 23K.

Comments (20)

Leave a comment

Dean, if you’re really good I just might code a PHP version (a pretty big ‘might’ though). Actually, I do something similar with my CSS file. It’s actually a human-readable PHP file, but I use PHP’s output functions to return it as one long line when it’s requested by the browser. I can save 2kb on every page load without having to sacrifice readibility (albeit, I had to sacrifice syntax highlighting since it’s a PHP file and not a CSS).

  • Comment by: Dante
  • Posted:

This great tool doesn’t seem to work (anymore) in FF, if I’m not mistaken it did still work a few days ago.

The packed code is full of ‘block’ characters and ends up being larger than the original source.

Thx
  • Comment by: Jannes
  • Posted:

Jannes, it is working for me. Can you tell me more about the Firefox platform you are using (version no. MAC/Windows)?

  • Comment by: -dean
  • Posted:

I think I am also having the behaviour that is experimenting Jannes.

I am using PC+WindowsXP SP2+Firefox 1.0.4(Gecko/20050511). The OS and browsers are configured as es-ES language (charset: ISO-8859-1).

Regards,

Andrew

  • Comment by: knocte
  • Posted:

Dang it. I just can’t recreate this bug.:-(

  • Comment by: -dean
  • Posted:

Love the algorithm Dean,

Just wanted to post a condition that I found where the algorithm causes the JS to error.

In a script I’m using (but didn’t write) the author sometimes doesn’t use { and } around his if/else statements, which seems to be ok, except in this situation:

if(fl)
    fl.parentNode.insertBefore(fe,fl.nextSibling);
else
    // otherwise, attach it after the field tag.
    n.parentNode.insertBefore(fe,n.nextSibling);

In the packed JS I get an error that “elsen” isn’t defined. I’m guessing that the presence of the comment there is causing the problem, because it doesn’t have an issue with other bracket-less if/else’s without comments (that I’m aware of). Adding brackets fixed the error. Removing the comment also fixed the error.

I packed the script using the web interface (this particular script won’t successfully pack with the .net app) using Fast Decode, Normal Compression and using FireFox 1.0.4.

  • Comment by: Jay
  • Posted:

Doh! A bug in the algorithm! I’m heartbroken.:-(

I’ll go fix it though. I’m replacing line comments with an empty string. I should probably replace them with a space.

Thanks for the report!

  • Comment by: -dean
  • Posted:

Hallo!

Your nice packer doesn’t work when the option “fast decode” is disabeled.
I’m using opera7.56, opera8.01, ff1.x, msie5.01 on win98.

thanks for your work, Jörgen

  • Comment by: j.j.
  • Posted:

Jörgen – I’ve fixed this but haven’t rolled out the new version yet. Thanks for the report.

  • Comment by: -dean
  • Posted:

hi, i like the new version!

unfortunately, i am experiencing the same bug that jannes and andrew report. i am using firefox 1.0.6, windows xp sp2. i *do* have a lot of extensions installed, though… i can type up a list if you like. i can also send a sample of the buggy output if it’ll help.

but the .NET application version is great to have locally!

  • Comment by: bunnyhero
  • Posted:

oh, another data point… when i use ‘(none)’ for encoding type, the output still has all comments and whitespace!

also, the strange ‘block’ characters appear to be ASCII 01, according to my text editor.

  • Comment by: bunnyhero
  • Posted:

me again, sorry to clutter your comments. anyway, more data: i tried it on my other windows xp sp2 machine, same version of firefox, same extensions: no bug. i went back to the machine exhibiting the bug, made a new firefox profile: no bug in the new profile!

i wonder if it’s a firefox bug…

  • Comment by: bunnyhero
  • Posted:

ok! i found out how to reproduce it!

  1. go to about:config
  2. change javascript.options.strict to true
  3. reload packer page and try encoding… you get the buggy behavior

change javascript.options.strict back to false, and refresh packer page to ‘fix’

  • Comment by: bunnyhero
  • Posted:

Well done Mr Bunny!

I just looked up that option and it supposed to turn warnings on/off for the JavaScript console. How this affects packer output is a mystery. Still, at least I can test it now. Thanks!:-)

  • Comment by: -dean
  • Posted:

I tryed to port your great javascript packer to PHP but it’s to hard for me:-(So I tryed to convert PERL version to PHP but my knowledge in PERL not allow me.

So if someone know PERL and PHP may be he will success to make this port.

Some volunteers ?

  • Comment by: Naonak
  • Posted:

OK, so I’m a year and a half late on adding a comment… anyway…

How does the packer handle Internet Explorer conditional compilation? Almost all of my scripts use conditional compilation so I really need the packer to detect that a comment is indeed a conditional compilation comment and leave it well alone.

Wow, a year and a half after the fact, man am I’m fast these days or what!

Thanks in advance, Brian.

@Brian – packer, like pretty other compressors does not respect conditional comments. The next version does though.:-)

  • Comment by: -dean
  • Posted:

Thanks for the info. I’m looking forward to V3!

Dean, the packer is an extremely useful tool. I was wondering, is it possible to have a relese that embeds the encoding logic in a self contained webpage (like http://www.tiddlywiki.com/)? Then we could save the webpage itself in an encrypted form.

  • Comment by: Soumen Bhattacharya
  • Posted:

@Soumen – OK. I’ll do that for version 3.0.

  • Comment by: -dean
  • Posted:

Comments are closed.