Skip to content

SCOBot removal of jQuery dependency (Audit) for Version 4.0.0

Mark Statkus edited this page Jul 24, 2014 · 11 revisions

Recently, it came to my attention there are other popular frameworks being made. This is happening in a garage, back room at your favorite tech giant, or some theoretical new paradigm thats all the rage. One unfortunate side effect of using a framework, or added libraries, is you end up with a lot of unnecessary overlap with functionality possibly present in your own work, or those other extensions or plugins you've also adopted. To my knowledge I haven't seen anything that really deals with the fact that you could be using something that already detects objects vs an arrays, or returns a random number, formats data etc ... You'd end up with having to create wrappers and hooks to fully pull it off, or just quit replicating so much code everywhere. Course sometimes you actually have to get your hands dirty.

jQuery is a great go-to library for solving cross-browser issues, traversing the DOM, but often if we're forcing someone to adopt jQuery in a project they already had a framework in, just to use SCOBot, we should pull out the dependency if its reasonable. Solving problems is why front end, and backend frameworks even exist. But, if you're unfamiliar with even having any of the symptoms a framework is trying to solve, you may just find yourself exploring why people are building, and most often giving these things away for free.

You also may just be finally looking under the hood and or curious as to what this framework you've used for the past few years is even doing.

SCOBot makes use of the following jQuery functionality which in some respects has proven API's that had to hold up to the test of time, and generous contributions by the open source community.

  • $.extend
    • $.isFunction
  • $().triggerHandler
  • $().on
  • $.isPlainObject
    • $.isWindow
  • $.type
    • class2type
  • $.isArray
  • $().bind
  • $(obj)

Doesn't appear like much, but it actually was quite a bit. After a rough estimate, it came out around 150 lines of code that SCOBot was directly relying on. If you were to actually trim out comments and such it wasn't really all that much.

... Then came listening and triggering events, and they are fired on / from JavaScript objects. Native JavaScript does not allow you to do this, you can only 'listen' to DOM Elements. Researched several examples of this online, and not withstanding browser compatibilty located an implemenation that seemed to asist with a rather low foot print.

Total size of the code after you minify/pack was 3.9KB vs having the larger JQuery library at 95KB.

Tested: Mac OS X 10.9.4 - Safari 7.0.5............OK FireFox 30.0............OK Chrome 36.0.1985.125....OK

Windows XP - IE 8.0.6001.18702.......OK Chrome 35.0.1916.153 m..OK FireFox 20.0.1..........OK

Windows 7 - IE 8....................OK (cosmetic timestamp differences) IE 9....................Untested Chrome 36.0.1985.125 m..OK FireFox 31..............OK

Windows 8.1 - IE 11.0.9600.16663......OK Chrome 35.0.1916.114 m..OK FireFox 31.0............OK