Archive for June, 2009
Finally found what I have been looking for: JavaScriptMVC
I’m very passionate about the code I write, and with the coming of jQuery I really began to love Javascript. But the Javascript I wrote was more of the procedural kind. I tried to split it up per page or user control but it still felt bad. For pages with a lot of interaction the JavaScript files grew very quickly over a couple hundred LOC. There is the possibility to split these up, but the problem that then arises is that the browser launches a request for each javascript file. And most (older) browsers have a suprising low amount of simultaneous request (I thought it was around 2 or 3, it was certainly below 5). So each file I added to make my application more maintainable resulted in a slower application. Not a good situation to be in.
I was constantly on the lookout for something that could easily minify and merge all my JavaScript files and still keep maintainability while developing. I had read solutions of people who had a build task that did this for them. But that seemed like a pretty vulnerable system. The build script has to create a new file on a certain location and has to change your pages so they include the correct javascript file (the newly generated one). So I lived with the pain.
Until I read about JavaScriptMVC on Ajaxian and decided to check it out. What is JavaScriptMVC? I’ll quote from their site:
JavaScriptMVC is a framework that brings methods to the madness of JavaScript development. It guides you to successfully completed projects by promoting best practices, maintainability, and convention over configuration.
So it uses some conventions and the MVC pattern to give you the ability to manage your JavaScript code. But the biggest thing I like so far is the possibility to run in different modes (development, test and production) and if you run in production all your javascript including your external libraries like jQuery get minified and combined into one javascript file. Yes that’s right even if you have a dozen javascript files, after minifying them you’ll only have one file called production.js left. The big advantage is that the browser only has to do one request to the server to load all of the javascript. You know what that means, faster loading times!
If you write a lot of JavaScript code, check out JavascriptMVC right now. I’ll be writing more details about the framework in the coming weeks as I’m still in the process of learning it.
Book review: jQuery in Action
I started reading this book about 6 months ago. After reading it half way through I stopped and start reading a newly purchased book. The reason that I stopped reading was because I was excited and impatient to start reading the new book, it’s a problem I have every time I purchase a new book. After finishing some books I realized that jQuery in Action was still lying around, and because the new project I’m working on depends heavily on jQuery, I decided to pick up the book where I left off and finish it.
If you use jQuery in your day job or you are interested in JavaScript development in general this book is really for you. I read this book after several months of jQuery development experience and still learned a lot about the framework.
The authors of the book recommend reading the appendices first before getting into the real stuff. They are a very good start for people who are not that familiar with JavaScript and get you up to speed on some essentials of the language like the JavaScript Object and how functions and closures work. These concepts are explained in a very clear way.
After the appendices you dive right into the jQuery goodness with the explanation of the pure basics. Selectors are a very important part which is handled in detail. Via events, animations and effects they show the basic utility functions that are built-in in jQuery. Although the whole book is a very interesting read chapter 7 really pops out and shows how you can write your own plugins, which can result in a lot of code reuse when used properly. The book is finished with how to do Ajax calls with jQuery and some of the best jQuery plugins.
I think it’s quite clear by now that this book is a good read for all levels: beginner, intermediate and advanced. I’ve learned a lot about jQuery that made my job a lot easier. And I think that’s the reason why we read technical books, broaden your horizon and learn how to use framework and tools more efficient. The authors certainly succeeded with this book.
To close I would like to list my 5 favorites things I learned or learned more about while reading the book:
- Selectors, although I already knew a bunch about supported selectors I learned some new ones that I didn’t know of
- animate() that enables you to create your own custom animations and gives you endless possibilities
- $.grep() can be used to filter arrays
- $.post, $.get, $.ajax, … all the different features in jQuery that support ajax calls to the server and a reference of all the different options.
- Live Query plugin, which can monitor if certain events occur on elements which match a certain selector. The good thing about this plugin is when adding new items to the page that match the selector, you don’t have to bind the events for this new item. The plugin takes care of that.