OK. Call me anal or something but I don’t like the way coders so frequently leave “fat” in their javascript. Which might be fine if everyone was on a T1 line or something, but they’re not and we need to be nice and thoughtful and stuff.
To that end, I’ve gone to the trouble of playing with the Scriptaculous JS library and Prototype.js (which comes bundled with it) and I’ve managed to pack the whole lot into one single Javascript file, weighing in at just under 50Kb.
So now you can link to just one single JS file, wherever you want the full DHTML/AJAX power of Scriptaculous.
In case you’re wondering, Prototype.js weighs in at 47Kb and the main Scriptaculous files total 91Kb. That’s a total of 138Kb shrunk down to 49Kb or a drop down to 35.5% of the original size!
Note: the only Scriptaculous file I omitted was the unit testing one. It’s not a core file anyway. Plus it would have blown the size out and I really wanted to keep under 50Kb… which does have a lovely ring to it.
Download the file here (right-mouse-click and save to disk): scriptaculous.shrunk.js
USAGE: Because I’m using the extended ASCII character set to push the compression a little hard to get it all in under 50Kb, you need to tell the client you’re using that character set. This just means adding the charset attribute correctly to the HTML head of your pages (the first line is to keep IE happy):
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<script src="wherever/scriptaculous.shrunk.js" type="text/javascript" charset="ISO-8859-1"></script>
Hope you enjoy it!
Oh, and a big hat-tip to Dean Edwards for the “Packer” magic.
9 Comments
you were wondering... I believe in rewarding commenters!
I’m using a javascript to get mouse coordinates which is working however, I want to pass these values to rmagic using rails framework. Any idea how I might accomplish this?
Peter, I’m not the best person to ask, as I am not a Rails afficionado at all. There is a discussion list you can subscribe to called rails-spinoffs where all the real gurus hand out. Sign up for that here:
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Hi Alister,
Nice work on the scriptaculous.shrunk.js.
Do you have an updated version?
Cheers,
Trav.
Trav,
Not right now. I did the initial one manually and it literally took hours.
The automatic way to do it would be to push it thru the Dojo ShrinkSafe app, then thru Dean Edwards’ packer. That would be ideal. But something breaks in prototype.js when you try and do that. I think it’s because prototype.js uses some very “interesting” coding in places that ShrinkSafe can’t handle safely. D’oh!
I’ll keep looking into this tho, and keep posted for an update.
- Alister
I don’t know if you read comments on this old articles,but:
Do you plan to repeat this with the current version of proto and scriptlicous?
@Martin - thanks for your comment. I would dearly love to maintain a shrunk version of these files here, but there are “issues” with Prototype. Basically, the shrinking breaks the JS, introducing errors. It has to do with some very particular JS code used in Prototype. I emailed Dean Edwards for help on this, but he never replied. Sad.
That said, I’ll have another look at the latest versions and see what can be done. It’s worth another go.
HI Alistair, I’ve come to realise that any effort to shrink prototype and scriptaculous are well worth it - my server CPU maxes out to 100% when a site loads prototype and scriptaculous’ files, even when gzipped! Strange, given that an image file of the same weight doesn’t have this effect.
I’ll give your file a go!
Do you plan do this with newly versions of prototype/scriptaculous?
Ridrigo and others who have asked… I would love to update this as it goes, but a) I have chosen jQuery over Scriptaculous a LONG time ago (it’s just a LOT better, in my mind) and b) I had problems with the compression that I have been unable to overcome.
So I think the short answer is I cannot help you. For which I apologise.
-Alister
12 Trackbacks/Pingbacks
Posted 38 years, 4 months ago
Posted 38 years, 4 months ago
Posted 38 years, 4 months ago
Posted 38 years, 4 months ago
Posted 38 years, 4 months ago
Posted 1 year, 3 months ago
Posted 1 year, 3 months ago
Posted 1 year, 3 months ago
Posted 1 year ago
Posted 38 years, 4 months ago
Posted 38 years, 4 months ago
Posted 2 weeks ago
Post a Comment