We've got a crapload of Javascript that could use real compression to help crush it down to nice bite sizes.... I haven't seen any around in the bit of searching I've done.. hoping someone has a secret stash somewheres...
gz/bz2 library
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
gz/bz2 library
Would anyone know of a (small) implementation of a gzip or bzip2 decompressor (or library) written in Javascript?
We've got a crapload of Javascript that could use real compression to help crush it down to nice bite sizes.... I haven't seen any around in the bit of searching I've done.. hoping someone has a secret stash somewheres...
We've got a crapload of Javascript that could use real compression to help crush it down to nice bite sizes.... I haven't seen any around in the bit of searching I've done.. hoping someone has a secret stash somewheres...
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: gz/bz2 library
Does it have to be gzip?feyd wrote:Would anyone know of a (small) implementation of a gzip or bzip2 decompressor (or library) written in Javascript?
We've got a crapload of Javascript that could use real compression to help crush it down to nice bite sizes.... I haven't seen any around in the bit of searching I've done.. hoping someone has a secret stash somewheres...
Kinda of weird request...but hey...why not right?
Anyways, this annoys me when people do this...so I'm being a hypocrite, but...
Have you tried searching for: http://www.google.ca/search?hl=en&q=jav ... sion&meta=
Just incase you didn't search these keywords...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
well... it doesn't have to be gzip, but it does need to be a compression that php can perform very quickly (read compiled command, preferably built-in) .. of which there aren't many, none of which seem to have libraries built in Javascript (yet.)
Google was of no help that I could see, hence my posting a new thread.
Thanks though..
Google was of no help that I could see, hence my posting a new thread.
Thanks though..
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I'd never really thought about this... see server side gzip compression would help if the browser supported it but apparently it can cause issues with CSS/JS (not sure why
).
I've been googling too but I don't see anything myself. It'd be interesting to see if somone could grab an implementation of gzip in another language and use it to write a JS implementation.... I'd guess that performace would be poor but you only need to run it once at page load (and it would be nice to cache if that were possible).
It's possible to really cut down on file-size by converting all vars/functions to really short, meaningless names (in production only) and removing just about all whitespace but that's by no means *real compression*.
I'll be interested to see if this has been done or if someone could implement it.
I've been googling too but I don't see anything myself. It'd be interesting to see if somone could grab an implementation of gzip in another language and use it to write a JS implementation.... I'd guess that performace would be poor but you only need to run it once at page load (and it would be nice to cache if that were possible).
It's possible to really cut down on file-size by converting all vars/functions to really short, meaningless names (in production only) and removing just about all whitespace but that's by no means *real compression*.
I'll be interested to see if this has been done or if someone could implement it.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
right. We do the white-space thing already, I'm considering the on-the-fly renaming, but real compression would help.
The major reason it can break CSS and Javascript is mostly due to poor creation of the code. For instance, not placing semicolons where they should be required, but due to very lax implementations and loose strict handling of code. Here's a quick example:With white-space removed, the above Javascript will error, whereas as-is, it will not in most engines (reasons above).
Compacted:
Why does it break?
There's a semicolon missing after the function definitions:
...turn a*r/g%s;};SomeType.p...
The major reason it can break CSS and Javascript is mostly due to poor creation of the code. For instance, not placing semicolons where they should be required, but due to very lax implementations and loose strict handling of code. Here's a quick example:
Code: Select all
SomeType.prototype.SomeMethod = function(a,r,g,s) {
return a * r / g % s;
}
SomeType.prototype.SomeOtherMethod = function(a,r,g,s) {
return a / r * g << s;
}Compacted:
Code: Select all
SomeType.prototype.SomeMethod=function(a,r,g,s){return a*r/g%s;}SomeType.prototype.SomeOtherMethod=function(a,r,g,s){return a/r*g<<s;}There's a semicolon missing after the function definitions:
...turn a*r/g%s;};SomeType.p...
Re: gz/bz2 library
I completely misunderstood your goal from the first sentence.feyd wrote:We've got a crapload of Javascript that could use real compression to help crush it down to nice bite sizes.... I haven't seen any around in the bit of searching I've done.. hoping someone has a secret stash somewheres...
You don't need a js implementation of gzip - you need a way to gzip compress your javascript files, yes?
If so: http://www.fiftyfoureleven.com/sandbox/ ... ip-method/
Usable for javascript libraries, css, and more.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It's a bit of both, potentially.. we have to do some testing but there's a path of gzipping the code with a live decompression, then there's gzipping the page itself.. We likely need both as a browser may support gzipped content natively, or we need to transport the content normally but gzipped internally to unpack itself on the client side.
A basic page in our application can easily be 100K, with is transporting in much more via Ajax as they move around (we clean out "old" data after a while to keep the overall footprint fairly small)
There's a small amount of security-by-obscurity here too. (Not my initiative, just my task to take care of.) Which is mostly a side-effect of doing the compression inline. Sure, a "smart" person could unpack it quite easily... again, I'm not personally after that, because I think it's silly.. however it is my task to implement it. If only to remove some casual "theives" ...
A basic page in our application can easily be 100K, with is transporting in much more via Ajax as they move around (we clean out "old" data after a while to keep the overall footprint fairly small)
There's a small amount of security-by-obscurity here too. (Not my initiative, just my task to take care of.) Which is mostly a side-effect of doing the compression inline. Sure, a "smart" person could unpack it quite easily... again, I'm not personally after that, because I think it's silly.. however it is my task to implement it. If only to remove some casual "theives" ...
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Check this out...
http://dgrin.com/showthread.php?t=22928
It is very simple and it does work.
BTW, if you can get the server admin to enable gZip on the server itself for all http output then everything including your javascript will be compressed automatically.
The other thing is to just use the include function in the php script to include the js (as long as they are not applets) and css files (just remember to properly delimit them with ?><? tags). Sure people will be able to SEE the source easily but it will be compressed automatically with the rest of the html being sent.
http://dgrin.com/showthread.php?t=22928
It is very simple and it does work.
BTW, if you can get the server admin to enable gZip on the server itself for all http output then everything including your javascript will be compressed automatically.
The other thing is to just use the include function in the php script to include the js (as long as they are not applets) and css files (just remember to properly delimit them with ?><? tags). Sure people will be able to SEE the source easily but it will be compressed automatically with the rest of the html being sent.