May 20th, 2011 Posted by Dave Mahon
If you’ve ever had an autocomplete field, you’ve had to deal with reducing server load and improving perceived performance for the user.
Most of the time, we rely on the server to store the data for us and retrieve it quickly and/or return an HTTP 304.
The cachejs library flips that model on its head and handles the caching client-side using your choice of storage. Currently, it supports HTML5 Local Storage, a variable in the current window, or cookies, but you could conceivably add additional engines.
Further, its only external library is JSON2 for transparent serialization/deserialization, but this could readily be swapped out for your pre-existing framework by editing the JSONWrapper declaration in stores.js.
The only notable downside to the implementation that I have found is that it creates at least four global variables, when it could easily have been implemented as members of a single object.
January 14th, 2008 Posted by Don Albrecht
A question emerged out of my boredom on my flight yesterday. Which is faster, implicit vs explicit conversion. Most javascript developers use implicit conversion out of habit. For example:
!!x; instead of Boolean( x ); and x + “”; instead of String( x);.
I decided to try an experiment for myself and record the performance of casting a number to a Boolean or String on my Windows box in Safari 3, Firefox 2, Opera 9 and IE 7.
The Verdict:
Implicit conversion wins handily, demonstrating over a 7 fold performance increase in one test. Overall, the performance gain for using implicit conversion averaged out to 53% across browsers after 10 tests.
The Numbers:
| |
Implicit Boolean |
Explicit Boolean |
Implicit String |
Explicit String |
| Firefox 2 |
0.162 |
0.312 |
0.248 |
0.358 |
| IE 7 |
0.042 |
0.100 |
0.074 |
0.152 |
| Opera 9 |
0.030 |
0.088 |
0.020 |
0.142 |
| Safari 3 |
0.028 |
0.036 |
0.074 |
0.100 |
| Cross Browser Average |
0.066 |
0.134 |
0.104 |
0.188 |
You can find the code I used after the jump.
Keep reading →
November 27th, 2007 Posted by Don Albrecht
What is it:
FastInit is a small JS file to create a Faster window.onload. It implements a powerful onload function queue that fires once teh dom is ready and before all images have been downloaded. Ideally, this results in a dramatic decrease in a pages initialization time.
How it Works
You any functions to the queue by using the FastInit.addOnLoad( function 1, function 2, …); function. All functions are fired in the order in which they were added to the queue. addOnLoad can be called as many times as is necessary. It fails gracefully to standard handlers if the browser doesn’t support the faster methods.
Requirements
As of version 1.4.1 the need for Prototype has been removed freeing the code for use in any project where a speedy onload method is needed.
Check it out here:
http://tetlaw.id.au/view/javascript/fastinit
November 2nd, 2007 Posted by Don Albrecht
D’bug has published a wonderful list of techniques for abbreviating Javascript and improving performance.
You can find the article here:
http://blog.reindel.com/2007/11/01/javascript-shorthand-tips-and-tricks/