Alister Cameron // Blogologist

Changing the world. One blog(ger) at a time.

Prototype.js + Scriptaculous in one file under 50Kb!

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.

10 Comments

Note: Commenter website links are not no-followed, in case
you were wondering... I believe in rewarding commenters!

  1. Posted 2 years, 5 months ago // Permalink

    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?

  2. Alister
    Posted 2 years, 5 months ago // Permalink

    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

  3. Posted 2 years ago // Permalink

    Hi Alister,

    Nice work on the scriptaculous.shrunk.js.

    Do you have an updated version?

    Cheers,
    Trav.

  4. Alister
    Posted 1 year, 12 months ago // Permalink

    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

  5. Martin
    Posted 11 months ago // Permalink

    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?

  6. Alister Cameron
    Posted 11 months ago // Permalink

    @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.

  7. Posted 6 months, 2 weeks ago // Permalink

    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!

  8. Posted 5 months, 2 weeks ago // Permalink

    Do you plan do this with newly versions of prototype/scriptaculous?

  9. Alister Cameron
    Posted 5 months, 2 weeks ago // Permalink

    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

  10. Posted 1 month, 1 week ago // Permalink

    Nice! I’ll be sure to use this in some projects. How long did this take you, out of curiosity?

12 Trackbacks/Pingbacks

  1. links from Technoratialguien había fusionado a prototype.js y script.aculo.us, pero desde hace unos días su web se encuentra inaccesible y para no perder la oportunidad me puse a googlear un poco y descubrí unas interesantes fusiones de estos dos script, vamos a ello: scriptaculous.shrunk.js - 50KB Ya un poquitin viejo y a desveladas: “5 January 2006 – 1:23 am”. . Protoculous - 54.6KB Vía: http://bloke.org/, y un poco más gordito que el anterior pero mucho más reciente. . ProtoPacked

  2. links from Technorati because it’s a lot less bulky and I like programming with it better. However I can’t be arsed to change everything which is why I decided to just keep it for now and optimize it. Luckily I found Alister Cameron’s post ‘Prototype.js + Scriptaculous in one file under 50Kb!’ which made a hell of a difference. If your site uses Prototype and Scriptaculous just like mine I highly recommend using Cameron’s optimized script. So I went with Cameron’s script and pasted my own JS code at the bottom of it. I’m serving it to you

  3. links from Technorati Alister Cameron has combined the Prototype and Scriptaculous libraries into one condensed file:http://www.alistercameron.com/2006/01/05/prototypejs-scriptaculous-in-one-file-under-50kb/ Web 2.0 Technologies

  4. links from Technorati Alister Cameron has combined the Prototype and Scriptaculous libraries into one condensed file:http://www.alistercameron.com/2006/01/05/prototypejs-scriptaculous-in-one-file-under-50kb/ More on Ajax » , Prototype » Posted by Andre at 07:33 PM | Permalink

  5. links from Technorati Alister Cameron has combined the Prototype and Scriptaculous libraries into one condensed file:http://www.alistercameron.com/2006/01/05/prototypejs-scriptaculous-in-one-file-under-50kb/ More on Ajax » , Prototype » Posted by Andre at 07:33 PM | Permalink

  6. Kramer auto Pingback[...] Prototype.js + Scriptaculous in one file under 50Kb! | Alister Cameron, Blog Consultant [...]

  7. Kramer auto Pingback[...] JS libraries down from 138Kb to 49Kb. Grab the one single fat-free javascript file… for free! http://www.alistercameron.com/2006/01/05/prototypejs-scriptaculous-in-one-file-under-50kb/ [...]

  8. Kramer auto Pingback[...] http://www.alistercameron.com/2006/01/05/prototypejs-scriptaculous-in-one-file-under-50kb/ [ Show » ] Chris May [31/Jan/07 11:05 AM] Actually, the previous one is 47K ! Here’s the whole lot (alegedly) in 50K. http://www.alistercameron.com/2006/01/05/prototypejs-scriptaculous-in-one-file-under-50kb/ [...]

  9. Kramer auto Pingback[...] read on optimizing prototype.js - found via google - will test and report in here - if it works: http://www.alistercameron.com/2006/0…le-under-50kb/ http://www.habtm.com/articles/2006/0…g-prototype-js Last edited by dollars5 : Today at [...]

  10. links from TechnoratiDans ma boîte à outil basique, j’y mettrais le chargement par insertion DOM, la gestion des cookies, timeout, addevent et domready. Ces fonctions primitives sont très faciles à écrire. ↑ Parmi les pages intéressantes que j’ai trouvé,Alister Cameron propose le pack prototype.js + scriptaculous.js(avec quelles extensions ?) packé en un seul fichier. Notez sa solution sur la gestion de charset appelé. [IMG]

  11. links from Technoratiview blog

  12. Kramer auto Pingback[...] gelegen haben. Auf der Suche nach anderen Versionen bin ich dieses Teilchen gestoen: http://www.alis…-under-50kb/ In mageren 50kb ist alles drin und o.g. accordion funktioniert auch - Wer es also etwas schlanker [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
  • A Few Words About Me

    If you haven't worked it out yet, I'm passionate about blogging! I build blogs, I optimize and market blogs, I coach bloggers, and in the gaps I blog about blogging. Phew!

    I am a capable designer, programmer, marketer, writer, trainer/educator and strategist, obsessing over this internet thing since 1995.

    If you're serious about blogging, I would suggest taking some time to read my blog. Then, if you want more of me, get in touch...

    Contact details »

  • Look Who's Been Here!

  • My Posts in Your In-box!

    Enter your email address here for instant updates in your inbox, whenever I post something new.
    Your email address is in safe hands. Relax!
© Copyright 2008 Alister Cameron. All Rights Reserved Theme // Sitemap // RSS