I hereby decree

by David LeMieux


Code libraries and frameworks are great. They provide so much of the heavy lifting that developing with them becomes easy and predictable. In most cases, code libraries are a perfect remedy.

In JavaScript, for example, jQuery not only provides a nice interface for dom manipulation, but also normalizes all the browser quirks so that, regardless of how a method is implemented, we know it will work. True encapsulation that benefits the developer. Unfortunately libraries like jQuery come at a cost, albeit an increasingly small one: Bandwidth.

There are things that can be done to offset this, like using a CDN hosted version of the file. There are also tools that can help you manage what features you need and only package those in. Modernizr has an excellent example of this on their download page. Still, there are cases like those I see at work where a 20Kb library takes up too much space.

At Flite I help develop our ad platform. Users can make ads for desktop and mobile web use and then traffic them via different channels. The IAB has numerous guidelines about Internet advertising, and one of them is about file size. Some ads, for example, have to be under 40Kb, images and all. Since we develop a platform that allows users to create ads in a drag-and-drop interface and customize it will different components and features we are, in effect, serving small web applications as ads. But for all the functionality we allow, we can't tap in to the features provided in a library like Angular JS, for example, because the minified file size is nearly 30K on its own, leaving very little room for other assets.

I understand this is a problem that is perhaps unique to our circumstances at Flite. It still holds true that if we can, in most cases, make our file sizes smaller then sites will load faster and faster load times mean more satisfied users. So my question is always this: At what point does using a library become useful?

If all I need to do is get an element on the page, there is no need to use jQuery with its selector interface when regular old Vanilla JavaScript can help:

var item = document.getElementById("theItemIWant");

But if I need to do something that becomes complex across multiple browsers and my own code would be bloated and inefficient, why not rely on a utility to do it for me?

Picking the right library or utility can also help when bandwidth is concerned.

There are resources out there to help find small libraries, like Micro JS, though not every library there has legacy browser support. It is also important to be aware that some libraries have dependencies on others - so a small MVC framework might actually depend on some other larger utility in order to function correctly.

Like I said before, maybe this is becoming less of an issue in the real world, but why not take a moment to consider how to make things more efficient and cleaner for our end users? Also, the exercise of solving code problems without a framework helps engender more respect for them and their utility.


blog comments powered by Disqus