and use a modular library like mootools.

Emil said on January 23, 2007

A lot of site today are currently using prototype and and their own site.js with all those ajax calls, hideMenu(); etc

Wouldn't it be easier just including proto & scriptaculo in the head-tag and then write inline javascript on only specific pages to reduce load time. Say you got a method call postAjaxTopic(); this function is only needed on forum.php and not in the entire project, but still "js gurus" say that you should avoid inline js.

Jonathan Snook said on January 23, 2007

Emil: it depends on how many pages said script will run. If the code is only ever used on one page then including an on-page <script> is fine (and preferred, imho). What most people mean when they say inline JS, is the stuff that's planted directly on to tags like onclick attributes or href's using javascript:.

Aaron Newton said on January 23, 2007

Jonathan, I also highly recommend NaturalDocs ( It's a perl script that will take your inline documentation and turn it into an html site that's searchable and browsable. I used this for Mootools docs and then again on our own (CNET) and it works great.

Put it together with something like /packer/ and you have a way to keep track of everything you write.

Andy Kant said on January 23, 2007

I agree with Uriel. When you're using something like Dean Edwards' packer, variable name lengths don't really matter. I usually keep most of my variable names pretty short though (obj, el, arr...).

Also, I can't agree more with you about hungarian notation. I didn't know that it had a name; I just thought it was something annoying that people did.

Poncho said on January 23, 2007

I totally agree. I'm a bit of a "best practices" junkie, with common tasks written as functions (sometimes namespaced depending on usage) linked out as a separate script. If a lot of script is needed only on one area of the site, it will only be included there.

I wrote all of my own javascript taking inspiration from various JS libraries until I descovered jQuery which is just about the right size at 19kb with functionality I wouldn't have to gumption to write on my own.

As far as variable naming goes, I always use short but descriptive names: element, anchors, fieldGroup etc.

I'd love to see what would happen if the guys behind jQuery, Prototype & MooTools collaborated on a JS framework. All of the above have similar goals but go about them in completely different ways.


Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.