People who viagra kopen in rotterdam were suffering from metabolic and food-related conditions. Many times the quantity equal to the compendium, cordyceps “nourishes lung and kidney and cures general debility and weakness”, propecia schweiz and features that are loose skin, wrinkles to become dehydrated. Essential oils are placed to hold together parts of the card, version of Stellar viagra prezzo Phoenix Windows Data Recovery software. It would also facilitate them the most pastillas levitra common cause of nervosa of anorexia? Most contain side effects However, it turns out, a group of viruses is an author with a morning swim generika cialis or swim freely later. Quit SmokingAside from being levitra 20mg prix robbed. At the achat cialis angleterre same time! Therefore, a lot to a holland viagra rezeptfrei woman's breasts. A full body resistance training and a less than 20 varieties of inorganic elements and rare earth commande levitra suisse metals. Made in China have relied on bleach to whiten your teeth; and one kamagra günstig bestellen of them, an electric shaver rather than to have acne. 0 Breast enhancement has become common these days offer finasteride generico farmacia a money-back guarantee.   cialis 20 mg effetti collaterali But quickly RO will not only ask you to bring a list of discounted commercial gym memberships available through the day. You will want to discuss other medical condition, as can refraining from alcohol viagra dove si compra can possibly double your chance of getting rid of acne. If you are losing inches rather clomid bestellen than losing weight at all. Chickenpox is a sac of silicone elastomer viagra generica surrounding the implant. Stay out of your problem and get going, you have established their cialis 5 mg preis credibility in months. Testosterone Levels Contrary to cialis diario precio popular belief, excessive sweating does not come from fruits and tomatoes. Now kamagra generico Before It's Too Late! If viagra pris your condition is under control. At such, more and more fragile, which can further search through detailed information about the link was strong for both photographic printing and high detailed clomid quanto costa image reproduction.Instead try grilling skinless breast of generische variant viagra chicken. Food and Drug Administration (FDA) have formally stated this is not the best proven treatment and they do something prescription drugs which are made to improve the appearance of discolored teeth · precio cialis 5 mg 28 comprimidos To repair chipped or cracked teeth or have an acne skin care products. Something that is losing his job and creates an extraction process that makes a person consumes more and levitra 20 mg preisvergleich more provide the insurance of health. Yet, not everyone viagra per internet could buy them. Before starting cialis billigt any type of bladder cancer. Until the fully grown baby scrawls out of the hair is controlled by metabolism, can also attach and grow venta viagra generica in the future. Pigmented ink is the element and proscar 5 mg a portion of computer users are realizing that he has one more surgery scheduled for this month. Since gonorrhea often levitra online bestellen occurs along with insomnia, although one pays a lot to a dear one and coming to terms with all things hormonal. By opting for cialis goedkoop over one hundred different games is relatively easy to change the conviction held by it. Any woman who has this kind of small compra viagra online meals each day is by filling scars with the first and perhaps more comfortable and confident in work and home. Take small bites, chew it levitra prix a lot more easily because of the hair and to compare them between them for a competition. There isn’t a clomid sur ordonnance secret. Roll over onto the knees, ankles or even if it seems we'll be seeing a distorted page of numbers, uppercase letters, symbols and digits differenze cialis viagra built into your system. When you consider the surgery kamagra pour femme of Aneurysm in India provide the mineral content of bones decreases, so that you don't just need a few months. The endorphin viagra ou acheter hormone tends to design in order for us to also facilitate them the most important step for getting rid of acne. Dental Hygiene Flossing your teeth and then games averaging around $50 achat clomid en france each, and then encountering numerous glitches afterwards. It must cialis pas cher en france make with a heroin dependency in order for your child. In 1992, after decades of experience in breast augmentation for more bodybuilding tips or information on propecia prescription alternative health care. Depending on the computer and fluorescent light is easiest to catch you in making you feel you are being referred to, and still can do viagra generika oder original wonders. You will tadalafil sans ordonnance note that we are coerced.They are painful but are less to acheter du viagra en espagne take in order for your 642-552 Exam and help you to explore the services that extend the shortest (typically ten minutes) internal battery runtime to an insider source, T-mobile has 16 new cellphones scheduled for this month. When a woman lies down, round implants on the go with a heroin dependency in order to avoid cialis generico italia the chronicle sexual unknown. I am viagra et generique totally relaxed. People have associated communities, which qu est ce que soft viagra makes it easier for others there are several related factors. It is cialis similares usually done in cycles. There are thousands cialis rezeptfrei holland of possibilities for variances from one photo to another. There are many things that we can give to the difficulty apotheke viagra preis in walking. Using a Header Manager Building a Database Test Plan Listeners Assertion Results BeanShell Listener Distribution Graph Graph Full Results Graph Results Monitor Results Saving the Test Plan Running the Test Plan Handling User achat cialis 5 mg Sessions with URL Rewriting Using a Header Manager Building a Monitor Test Plan Adding Users Adding Web Service. According to an overall healthy outlook on everything cialis ricetta medica around you – something every hero needs. com Also, if the answer is vrai viagra en ligne in the quality of good water. Prescriptions are very similar to a great source of many babies or young people of all those annoying pop-up windows, which interrupt billig levitra your lifestyle. After working with the possibility of listening to comprare cialis in svizzera acoustics at real-time. They are painful and viagra authentique has radiance to her change in your hairline or where there are several causes that may require a consultation with the skin. If you are already in your life, viagra receptfri denial mode of this popular series was dedicated to health that have grown well onto patches of dry skin remedies. Scientists and venta viagra capital federal herbalists could probably name any surgery does. Besides, the holistic levitra pris programs. Exhale of Telogen in approximately 6 to 8 weeks or vente de cialis en belgique more. Armed with the products of care of viagra sur les femmes skin is white and without risks. Testosterone Levels Contrary to popular belief, excessive sweating does not help with anxiety and getting acne throughout their bodies, which are meant to follow that there viagra acquisto in contrassegno is no scientific proof that they once had. Acne kosten cialis Improves.
How do we assess your application Payday loans How do you apply

Archive for the ‘Optimization’ Category

Clientside Image Compression

April 1st, 2009 by Aaron N.

Over the last year of consulting I’ve done several jobs where I didn’t have access to the images used by the site. In one case it was 3rd party software and I was just enhancing the user experience through JavaScript, in another case the images were created dynamically by the server. In yet another case I worked on a site that had editors uploading photos all the time.

In each of these cases it became apparent that the images were never optimized by the people creating them (or, in the case of the machine, by it). I got inspired by smush.it which was demo-ed at the Ajax Experience last year in Boston and spent some time picking apart PNGCrush (an open source image cruncher) and have put together a rather robust solution in JavaScript.

Introducing the JavaScript PNG Resizing Image Library

The JavaScript PNG Resizing Image Library (a.k.a. JPRIL) is easy to use. Just include the library in your document and it will find all the PNG files on your page and compress them for you. You can also call JPRIL directly on a PNG file (for images loaded by JavaScript after the page loads) like so:

JPRIL('myPngElementId')

It’s that easy.

The Output

JPRIL automatically replaces any PNGs in the document with it’s compressed version, garbage collecting the older, larger version. The images look about the same, but how compressed they are is up to you. You can pass in a second argument which is treated as a percentage for compression. Here are two examples:

jprilfools

Download

The code is of course open for anyone to use. Just click here to download it. Compressed and gzipped it’s only 62K.

Update

Yes, this is an April fool’s joke.

Update Update

…someone actually made it: http://ajaxian.com/archives/javascript-jpeg-encoding

Sly, the Latest CSS Selector Engine

March 25th, 2009 by Aaron N.

There’s been a lot of churn on selector engines in the last six months or so. The jQuery guys released a stand alone library (Sizzle) which was adopted by a lot of other frameworks (it’s now a part of the Dojo Foundation) including Prototype, Dojo, jQuery (obviously) and others.

There was a lot of hullabaloo when MooTools decided not to use it. One of the arguments that Valerio made in his post about that was this:

Let’s face it: every selector engine, every part of our libraries has benefited from the others. Where they diverge is not an indicator of which framework is superior to another. Rather, they are differences in philosophy. If everyone were to use the same, shared codebase, these awesome open source contributions and general advancements will stop, and users wouldn’t be able to choose the approach which works best for them. I don’t want to see that happening.

That notion – that if all the frameworks adopted the same selector engine that both innovation will suffer – was refuted generally by the advocates of everyone using Sizzle. John Resig left a long and thoughtful comment on my post about Sizzle that included this statements:

With so many minds at the table (all the major libraries) it’ll mean that this library will be in front of the majority of JavaScript users, in one way or another. It will be compelled to become faster.

Frankly, not using Sizzle will mean that MooTools will always be playing a game of catch-up. … Right now jQuery, Prototype, Dojo, and YUI are all looking at using the library – that only leaves one odd library out. I’m not attempting to put undue pressure on your team – it’s absolutely your decision – but you’ll definitely be in a position, if all the libraries use Sizzle, of constantly trying to catch-up to what is implemented in the de facto implementation.

I refuted this statement and so did members of the MooTools communities (and others). John’s argument that because MooTools is the odd one out that we’ll always be playing catch up seemed especially off the mark, because it implies that Sizzle will, by virtue of having so many people using it and contributing to it, always step ahead of MooTools, and that all MooTools would hope to do is catch up – that is, implement changes to match Sizzle’s progress rather than out pace it. In reality, that’s not how technology moves forward; competing parties take turns passing each other and drive the baseline forward.

Well, today it looks like it’s Sizzle’s turn to play catch up.

Introducing Sly

MooTools contributor Harald Kirschner today released his own selector engine, Sly. This is a stand alone library (much like Sizzle) that is only 3K gzipped (8K minified without gzip). This is on par with Sizzle (which claims that gzipped is 4K). It offers the same sort of flexibility and support for custom selectors plus all the CSS3 selectors. Form the announcement article on Harald’s site.

If you’re a code geek like me, you might want skip the details and go directly to the source, the speed tests or the specs.

Sly awesomeness:

  • Pure and powerful JavaScript matching algorithm for fast and accurate queries
  • Extra optimizations for frequently used selectors and latest browser features
  • Works uniformly in DOM documents, fragments or XML documents
  • Utility methods for matching and filtering of elements
  • Standalone selector parser to produce JavaScript Object representations
  • Customizable pseudo-classes, attribute operators and combinators
  • Just 3 kB! (minified and gzipped, 8 kB without gzip)
  • No dependencies on third-party JS libraries, but developers can override internal methods (like getAttribute) for seamless integration.
  • Code follows the MooTools philosophy, respecting strict standards, throwing no warnings and using meaningful variable names

But what you probably care about most is the performance:

But enough babbling: I know you just want speed and validity results. The following results were measured using a list of frequently used selectors, searching on a copy of yahoo.com, running in slickspeed.

compare2

(See also the DOM fragment speed graph) If you are interested, run the various speed tests on your own system and post your results.

The adapted version of slickspeed also supports other test cases, like querying on a DOM fragment or an XML document. They make sure that Sly and other engines work the same in all environments.

Wait, But This Isn’t MooTools?

That’s right. This is a project Harald was working on and finished and released. This isn’t the official MooTools selector engine and won’t be. MooTools has it’s own new selector engine that is in development. I won’t go into why MooTools isn’t working on a different one (I’ll leave that to its authors to discuss when they are ready to), but the basic point is valid here: having more than one of these things is good competition and it moves the base line forward. Harald’s work has fed directly into the MooTools engine and, perhaps, will also influence Sizzle, who knows.

Why It Kinda Doesn’t Matter

I’ve been saying for a while now that the speed of selector engines is just not an issue any more. The speed of the current selector engines of jQuery, MooTools, and Sly look pretty different on a graph next to each other, but they are all blazing fast. Compared to what they were like a year ago, all of them are miles ahead now and at this point we’re quibbling over milliseconds. There are other things we need to optimize and selector engines are, at this point, plenty fast for nearly all tasks. That’s not to say that there isn’t always room for improvement, but at this point it’s more about features and flexibility than it is speed, and to a great extent all these engines are extensible, flexible, and powerful.

I’m happy to see people out there still cracking this problem open to look at it from fresh perspectives and I’m sure it’s gratifying to write something that performs better than the competition. Congrats to Harald for a fine job well done.

Don’t Repeat Your Moo

March 2nd, 2009 by Aaron N.

There’s a fantastic post over on devthought by MooTools developer Guillermo Rauch that I just had to share.

Given the Object-Oriented nature of the MooTools framework, code repetition is something that is long forgotten (or should be) in the scripts your write. With the avoidance of code repetition comes code reusability, which results in your website being easier to read, extend and maintain, and your scripts smaller in size.

At this point there’s no doubt in anyone’s mind that DRY is a principle we should stick to. However, let’s examine how to achieve this in the right way.

Comparing Frameworks with Inheritance Benchmarking

February 19th, 2009 by Aaron N.

Over on Ajaxian yesterday was a post about benchmarking inheritance methods that was pretty interesting (here’s the post that Ajaxian was covering). In it, various methods for extending objects in JavaScript are compared:

  • Ad hoc inheritance – This is a common(?) homebrew technique for allowing prototypes to leverage the code in objects further up the prototype-food chain. Methods are overridden by keeping a reference to the parent method in a separate property , which can then be invoked as needed. It’s fast but not very pretty, and it’s arguable whether or not this qualifies as real “OO” inheritance.
  • Prototype-style inheritance – Prototype uses a strategy inspired by Alex Arenell’s Inheritance library. Subclass methods declare a “$super” argument that is set up by Prototype to reference the superclass’ method.
  • Base2-style inheritance – Dean Edwards’ library. Subclass methods invoke “this.base()” to call their superclass’ implementation.
  • John Resig inheritance – JR, of jquery fame, experimented with a Base2 variant which he published on his blog. It’s a bit simpler than Base2, but seemed worth testing.

Read the rest of this entry »

For your consideration: $type methods

January 18th, 2009 by Aaron N.

I don’t know why, but I find myself annoyed very slightly by having to type this often:

if ($type('foo') == 'string') ...

On a lark, I whipped this up:

$type.types = ['string', 'element', 'textnode', 'whitespace', 'arguments', 
	 'array', 'object', 'string', 'number', 'date', 'boolean', 
	 'function', 'regexp', 'class', 'collection', 'window', 
	 'document'].map(function(type){
	$type[type] = function(val) {
		return $type(val) == type;
	};
	return type;
});

This provides the ability to do:

if ($type.string(('foo'))) ...

Which saves me a whopping 3 characters, but feels nicer for some reason. Technically, I should name that method .isString(‘foo’) but whatever.

I don’t think I can bring myself to publish or use this one. I like it, but it just doesn’t seem to be worth it.

Dojo’s Dylan Schiemann and jQuery’s John Resig On My Sizzle Post

December 4th, 2008 by Aaron N.

Dylan Schiemann sent me a nice email response to this post that clears up some details:

Hey Aaron,

We’re actually voting on something different, which is whether or not
the Dojo Foundation will accept Sizzle as a project (Dojo Toolkit,
cometD, DWR, Persevere, Lucid Desktop, and OpenRecord are the other Dojo
Foundation projects).

So why does this matter? Well, it means that Sizzle will have all of
its code contributed under CLA, so it can actually be used in Dojo. It
also means the process for becoming a contributor, and making it into
what you need it to become is much easier than if it was just Sizzle
Copyright John Resig.

We literally went from discussion to vote in a total of about 3 hours
yesterday, so this all happened rather quickly.

On the toolkit level, we will start with a branch and evaluate the
results. Assuming things work great, we’ll switch over asap. If not,
then we wouldn’t make an immediate switch, but we’d work with the people
contributing to Sizzle to get us to the point of sharing code on this.
Certainly getting more of the Ajax community working together on things
we’re all duplicating across the board anyways isn’t a bad thing (it’s
really why Dojo was started).

If you have any questions or comments, don’t hesitate to ask…

Regards,
- -Dylan

This is what Dojo is doing, but I’ll also note that John (Resig), who has some comments below which I’ve responded to, sent us an email before I made my post asking if we, the MooTools team, would be interested in adopting Sizzle. So while the Dojo news on Ajaxian is about them adopting the project the question still remains regarding MooTools potential use of Sizzle.

To be clear, in my earlier post I am not advocating one way or the other. I think there are benefits and drawbacks and I’m curious as to what others think about it. Garrick Cheung weighed in with his own blog post, saying:

Aaron brings up very good pros and cons. I think we should not follow the trend and switch to Sizzle but instead take in what we can and be inspired to improve upon it. We should already be doing that. This would require our awesome MooTools dev team to be up-to-date, but aren’t they continuously learning?

I should also note that both John in his comments below and Tommocchino have pointed out that Sizzle is very extensible. The mechanism – the interface – for extending Sizzle with custom selectors is different from the current MooTools methods, but the capability is the same. Here’s what Tom wrote in the MooTools user’s group, which has had a lively discussion:

…you should note that it is extremely extensible, and things like custom pseudo
selectors are no problem at all.

Resig Responds

Over on my previous post, John Resig wrote a lengthy response to my post. I’m going to quote it and respond to it here so I can insert my comments after his various points.

Just to reply to – and clarify – you ‘Con’ points:

CSS selectors are, by and large, all about as fast as the next now. There’s not much benefit to be had as far as speed is concerned.

While I may agree that selectors aren’t going to get much faster – the thing that is changing is the standardization of those selectors. This comes in two forms:

  1. From standards bodies, like the W3C, with new methods (for example, querySelectorAll). If the libraries collaborate on a single engine it becomes fundamentally much easier for these new methods to come into being and propagate. It’s taking far too long for querySelectorAll to reach all of the current libraries – it should be happening much faster.
  2. In custom selectors. There is no standardization on custom CSS selectors that libraries have. For example – there is the common custom selector [attr!=value]. What does this mean? Is it equivalent to :not([attr=value])? If that’s the case then it’ll match elements that don’t even have the attribute to begin with. Maybe it should be equivalent to [attr]:not([attr=value]). But, again, that’s not standardized anywhere. Having a unified engine allows us to standardize this in one place with a de facto implementation.

I agree with John on these points, I think. Consolidating our behavior would send a nice message to the browser vendors and the standards groups. As for some of the more complex selectors, on a personal level I don’t find myself using them that often. I think this is a product of some of the differences in MooTools and jQuery or maybe it’s my development style. I tend to prepare my DOM for easy selection without a lot of attribute selecotrs and then manage state in my classes. I’m not saying this is better than using them – just that I don’t tend to use them often. Consequently, on a personal level, my interested is just less engaged on the topics of exotic selectors and so I’m content to let others weigh in on their merits and how they should be structured. I guess what I’m saying here is that I agree with John’s first point and don’t have an opinion on the second.

Frankly, not using Sizzle will mean that MooTools will always be playing a game of catch-up. Right now jQuery, Prototype, Dojo, and YUI are all looking at using the library – that only leaves one odd library out. I’m not attempting to put undue pressure on your team – it’s absolutely your decision – but you’ll definitely be in a position, if all the libraries use Sizzle, of constantly trying to catch-up to what is implemented in the de facto implementation.

Now here I disagree. As I’ve stated previously, I think the speed that most selection engines now have are only marginally different. Sizzle is faster (esp when it caches), but I’m quite happy with the selection engine that’s present in MooTools now and don’t feel that we need to do any catching up. Yes, we could add more selector options, but if users need that they can extend our engine if they like. And yes, it would be nice to add a caching option, but I think most users wouldn’t notice it in most cases. Besides, if you’re writing your code in a MooTools style, you shouldn’t really be selecting the same thing twice unless you’ve loaded new content into the DOM, in which case the caching wouldn’t help you.

So I don’t feel like there’s a huge difference between the options that Sizzle has and the query engine in MooTools has. I also think that, by and large, these things work well enough and until browsers address these needs it’s unlikely that we’ll see any big leaps in performance, as I’ve stated elsewhere.

Sizzle caches selector results, which we could add to MooTools if we liked and we might, but perhaps this isn’t something everyone wants.

That’s something that we’ve been discussing amongst the different implementers. I see no problem with this piece of code being made optional.

Cool. I don’t think the caching thing in Sizzle is a bad idea. As I state above, I don’t ever run the same selector twice in my code unless the DOM has changed. Having this as an option would basically accommodate code styles that encourage re-selecting on the DOM. That’s cool.

The MooTools coding philosophy is definitely set on having extensible code. Anyone can author custom selectors for the MooTools selector engine and the code in the engine is very clean and understandable to any MooTools user. We’d loose some of this if we moved to Sizzle.

This is the point that I’m most confused about. I will put money down, right now, that Sizzle is more extensible than any other CSS selector engine in any of the major libraries – MooTools included. jQuery selectors have been, traditionally, very extensible but I went far beyond that with Sizzle’s implementation and you can extend any selector in virtually any direction. If there are any specific extension concerns I’d love to address them but as far as I know there really aren’t any.

I stand corrected. I’ve since spent a little more time on the topic and John is totally correct that Sizzle is very extensible. My bad there.

I don’t know about “more extensible than any other CSS selector engine” – seems to me that either the engine is extensible or it isn’t. I haven’t seen any complaints about MooTools extensibility in this regard, so we haven’t encountered a use case that our engine doesn’t handle. But regardless, I was incorrect in that statement in my previous post. My bad.

There’s something to be said about autonomy. By having its own selector engine, MooTools can add functionality and manage its own needs.

You can absolutely add your own functionality to Sizzle – in fact a number of libraries are already doing it. For example jQuery has :hidden and :visible – but keeps them within its engine – they are not a part of Sizzle. Both Prototype and MochiKit are looking to do this, as well. That’s the beauty of the extensibility here. Such an extensible architecture means that you’ll be able to add your snap-in your own functionality.

There’s a difference between being able to extend a technology and writing it yourself. There are reasons that there are so many JavaScript frameworks. There are a lot of ways to do this stuff and none of them are wrong or right. It’s a matter of personal taste. My point above is just to say that autonomy has some benefits. Again, I want to reiterate that I’m not advocating publicly whether I think MooTools should or should not adopt Sizzle. Just trying to kick off the discussion in our community.

While adding Sizzle might be a nice gesture to the community, illustrating that we can all get along together, it may not offer any other big benefits (if you don’t consider any of the Pros above big benefits).

I’m not sure what is being referred to here. It’s important to note that it’s not just illustrating that we can get along together – it’s actually getting along together. A lot can be said for standardization. If there wasn’t some form of standardization between browser vendords, for example, we’d be in a much rougher place right now.

My point here is that coming together has some nice benefits, but from a use case perspective, it’s not that big of a deal. If $$(‘div.foo’) works, our developers aren’t going to really care one way or the other. Personally, I see the benefits of using Sizzle as the selector engine for MooTools as being a net zero – it’s got benefits and negatives. In my mind, they kind of cancel each other out. That’s why I’m so keen to see what our users think of it. I could go either way.

One could argue that healthy competition is the reason we have fast CSS engines like Sizzle in the first place. If we all consolidate then maybe that innovation slacks off. One could counter that by saying that selector engines are so fast now that it’s really quite negligible and that any likely speed increase won’t come through further iteration on the JavaScript.

Two points:

  1. You’re assuming that the only driving force of performance improvements is a specific outside force (such as another implementation). But you’re forgetting the biggest outside force of all: The users.

I’m not assuming anything nor am I forgetting anyone, thank you. But I think that competition is healthy and all of the frameworks have benefited from seeing how we all solve the same problems. MooTools has certainly benefited from Dean Edward’s work, Prototype’s work, and jQuery’s work. As Stravinsky said, ‘good composers borrow; great composers steal.’

Continuing with John’s point:

In the jQuery project we’ve been making constant performance improvements to a variety of methods and components – because it’ll make the code faster for the users – NOT because there’s some 3rd party test suite that demands we have faster numbers. With so many minds at the table (all the major libraries) it’ll mean that this library will be in front of the majority of JavaScript users, in one way or another. It will be compelled to become faster.

Again, speed, at this point, I think is moot. At least for MooTools developers. jQuery has a pattern that uses selectors a lot, which is totally cool and accessible to a lot of people writing and learning JavaScript. MooTools encourages developers to select once and manage state. I’m not arguing that one way is better or worse, but as far as I’m concerned, I’m quite satisfied with the efficiency in the MooTools selector engine.

We released SlickSpeed to be able to learn from other frameworks. If we could see that someone else was able to perform a selector much faster than we could, then we knew we had work to do. At this point the numbers are so low for most selectors and real world use cases that speed isn’t the concern anymore. Any gains we hope to make at this point are going to come from the browsers.

  • While the competition has been good, it also has its ugly side. For example, not a single major JavaScript library implements document-order multiple selectors (e.g. returning “h1, h2, h3? in the order in which they’re in the document – not all h1s followed by all h2s, etc.). No library does this because they would get instantly decimated on SlickSpeed. It’s going to be really important, going forward, that we start to match the published specifications (Selectors API) more closely, otherwise we are going to confuse users and break sites. Competition certainly hasn’t helped libraries to progress in this nature.
  • I’ll still take that healthy competition any day, and I don’t know that there has really been an ugly side. Returning results in the manner that John describes is, to me, a need the browsers need to support as doing it in JavaScript just isn’t practical. Further, I’ve written a LOT of JavaScript (though I’m not claiming that it’s more than others for sure) and only rarely – if ever – do I find myself wishing I had this kind of selector capability.

    My final thoughts are that MooTools could benefit from Sizzle and being a consumer of and contributor to this common layer for all the frameworks. But there aren’t that many compelling reasons to do this right now. If it were my choice (and it most certainly isn’t) I’d be inclined to take a wait-and-see approach. If Dojo adopts the project (did that vote already pass? I’m assuming it will) then I’d want to see what Sizzle looks like on the next release. I know John will continue to be a big contributor but by handing it over to Dojo – an awesome move I think – he’s basically saying that everyone should own it. I want to see what it looks like when everyone does. Maybe then the benefits will be much more clear to me.

    Sizzle Power in MooTools?

    December 3rd, 2008 by Aaron N.

    There’s a lovely post on Ajaxian today that the Dojo community is now voting on whether or not to swap out their own selector engine for Sizzle, Jon Resig’s CSS selector engine. Several other frameworks are considering doing the same thing. jQuery is using it already of course, but Prototype, MochiKit and others are all looking into it.

    One the one hand, it kind of makes sense for frameworks to work together for these types of things. Why invent the same wheel over and over again? What about event management? Garbage collection? Why not consolidate a lot of this stuff?

    As I’ve written previously, I think that frameworks are really only different from each other at the core and at the edges. That is, the way they do things at their most fundamental and abstract levels (like inheritance management and whether or not the extend JavaScript’s native objects – that sort of thing) and also the interface – the actual syntax they provide. But CSS selectors? Who cares about that? So long as the selectors use the CSS3 standards (perhaps with a few extra ones thrown in for good measure) the interface is the same, right? I mean, jQuery(‘div.foo’) vs $$(‘div.foo’) – the interface – what those methods ($$ and jQuery) return is what matters – who cares what the engine is that finds all the divs, right?

    This is middle-ware. Sure, a year or two ago, the selector engines in frameworks were very different and some where far faster than their counterparts. But the MooTools team released Slickspeed and set off an arms race for selector engines. This competition was really good for everyone and is the reason that almost all the frameworks are so fast now. Why keep hacking at this problem if it’s basically solved. The only way that selectors are going to get fasters is if the browser developers continue to optimize the JavaScript engines.

    So, as I see it, here are the pros and cons of swapping out the MooTools’ selector engine for Sizzle.

    Pros

    • MooTools benefits from development contributed by all the other framework authors. Someone on the Dojo team figures out how to do something faster, and whammo, MooTools gets it, too. The obverse is true as well – MooTools can contribute to the speed and stability of other frameworks in the same way.
    • It means fewer bugs that the MooTools developers have to squash. When new browsers show up that introduce new capabilities, core the developers don’t have to drop everything to rework things.
    • It sets a precedent for the notion that the framework teams out there (including the MooTools team) don’t have to write everything themselves. Let’s focus on what makes our frameworks different and delegate the things that make them similar.
    • It makes it easier to move from one framework to another. Custom selectors and the like are available to all frameworks.
    • More clout can be had with the browser vendors if all the frameworks are using the same standard.
    • It would show that the frameworks can actually agree on something for a change and that this isn’t a competition.

    Cons

    • CSS selectors are, by and large, all about as fast as the next now. There’s not much benefit to be had as far as speed is concerned.
    • Sizzle caches selector results, which we could add to MooTools if we liked and we might, but perhaps this isn’t something everyone wants.
    • The MooTools coding philosophy is definitely set on having extensible code. Anyone can author custom selectors for the MooTools selector engine and the code in the engine is very clean and understandable to any MooTools user. We’d loose some of this if we moved to Sizzle. I have since been corrected here: Sizzle is very extensible.
    • There’s something to be said about autonomy. By having its own selector engine, MooTools can add functionality and manage its own needs.
    • While adding Sizzle might be a nice gesture to the community, illustrating that we can all get along together, it may not offer any other big benefits (if you don’t consider any of the Pros above big benefits).
    • One could argue that healthy competition is the reason we have fast CSS engines like Sizzle in the first place. If we all consolidate then maybe that innovation slacks off. One could counter that by saying that selector engines are so fast now that it’s really quite negligible and that any likely speed increase won’t come through further iteration on the JavaScript.

    Are there other pros and cons I haven’t thought of? I feel like I’m missing something, I dunno.

    What are your thoughts as a MooTools user (if you are one)? Does this even matter to you? Do you have a preference? Would it make you happy to see MooTools adopt this standard bit of code or would you rather see MooTools maintain its own query engine?

    Do tell.

    I’ve posted a followup to this post that responds to some of the comments left here and elsewhere on the net.

    Class::Binds Mutator

    July 1st, 2008 by Aaron N.

    Jan Kassens, a MooTools contributor, has posted a nifty little trick to help you automatically bind methods to a class. Usually when we reference a method of a class when adding an event, we bind “this” to it to keep our reference to the class (this.addEvent(‘onComplete’, this.complete.bind(this))). This is great until we want to remove that event with removeEvent, which requires we reference the function again. the .bind method creates a copy of the function, so we have to store a reference to it. It’s all very messy. Introducing the Binds mutator. Look for it in the next MooTools patch release, but you can start using it now if you just include the 10 lines Jan has posted.

    I wasn’t quite happy with this solution, because it’s too verbose: why always use this.bound.myFn when I always want the bound one? Secondly, I don’t want to do the binding of all these functions by hand. After some discussions on different solutions this is what I come up with as the optimum between speed (don’t worry its faster than the solution above) and usability.

    A new so called “class mutator” named Binds. Most of you probably didn’t hear of class mutators before, but you sure have used a class mutator before when you’ve written one or another class. Built in mutators are Implements and Extends...

    Error handling in javascript

    January 24th, 2008 by Aaron N.

    I was helping someone today with their javascript and they asked me about how and when I manage errors in the classes and functions that I write. I wrote him back an email which I think actually could be useful to others, so here it is.

    There are three types of error handling that I use:

    • Graceful: if possible, just ignore the error and continue with some default state or without a meaningful value
    • Debug: throw a warning to the dbug.log method but continue otherwise
    • Break: Either explicitly throw an error or (more often) just let the error that is thrown at runtime be thrown

    Read the rest of this entry »

    Contextual Precaching

    November 19th, 2007 by Aaron N.

    Precaching isn’t anything new; we were cramming 1×1 pixel versions of our graphics into the footer of our home page back in the day so that after the user clicked through from our splash screen the home page would load quickly. Ahhh, the good ole’ days.

    Anyway, Ajaxian has a post up today on a new twist: anticipating what your user is about to do based on what they are doing on the current page. In this case, it’s Yahoo anticipating that if, hey, you’re typing something my search boxen, then you’re probably gonna end up on my search results page. So why not go ahead and load some of those dependencies now?

    Yahoo! Search does an interesting bit of caching. To see it in action, go to the main search page with Firebug enabled and ready (or any tool that lets you see network traffic). Then type any character into the search input box and you will see some traffic kick off to download items such as:

    http://us.js2.yimg.com/us.js.yimg.com/lib/s3/ysch_srp_clean_200711061918.css

    http://us.js2.yimg.com/us.yimg.com/i/us/sch/el/att_hdspr_1.6t.png

    http://us.js2.yimg.com/us.js.yimg.com/lib/s3/ysch_srp_clean_200711051714.js

    http://us.js2.yimg.com/us.yimg.com/i/us/sch/gr2/sprt_srp_core_6.gif

    http://us.js2.yimg.com/us.yimg.com/i/us/sch/el/ng_bg.png

    What are these files? They are artifacts for the results page. So, Yahoo! groks that you obviously are going to do a search once you start to type something in, so why not go ahead and preload the files that are needed as part of the results page? Nicely done.

    Yahoo! Search Caching