2010
01.10

To quote Eddie Izzard “Look, you’re British, so scale it down a bit, all right?”, well perhaps i should say “Look, you’re a validation framework, so scale it down a bit, all right?”. Recently i’ve been working on ALOT of javascript and experiences (reassuringly) from the past have come back to haunt me yet again. What am i talking about? Well it would seem that every framework starts out with the good intention trying to avoid repetition, but over time, someone adds a little here, and a little there and before you know it you have a behemoth of a framework which does things well out side the scope of what it should do.

How does this relate to javascript validation? Well after using quite a popular JQuery validation framework i noticed the size of the library minified as 29KB. This doesn’t sound a great deal but when you include a few frameworks like this, plus JQuery the page weights seem to get pretty big. Yes caching, gziping and content delivery networks will help but the first hit on these pages over mobile networks or on mobile phones and they can take quite a while to load. What i would like to see more of is smaller more directed frameworks/utilities that i can customise into what i want and keep page sizes to a minimum.

To this end i flippantly stated “It can’t be that hard” and embarked on writing a validation framework that will allow me to do most of what i need without the overhead. This is only a first stab that works for what i need, any comments on other validation types that i should support would be good.

Currently it supports… required (and ability to define a default value to ignore), patterns, less than, greater than, equal to, equal to other field and the ability to add custom rules. On top of this you can all specify rules that enable and disabled validation of a field. Currently the minified size stands at about 2k even tripling the number of rules would only take that up to about 4k.

I got the size down by only putting into the framework what really needed to be there. So what won’t it do? well it wont manage form click events for you, thats for you to decided how you want the validation to fire. It won’t do anything clever with the error messages, if you want something fancy write what you want.

Take a look at the code on git hub http://github.com/chrisabird/validate

No Comment.

Add Your Comment