Advice On Datejs Compression And Performance Tuning

January 22nd, 2008 | Code

Guy Fraser recently chronicled a series of his recommendations for Datejs compression and performance enhancements. Check it out.

One recommendation from Guy was to hold a reference to the Date.prototype in a local var, thereby saving characters and simplifying access to the prototype.


(function () {
    // Store prototype in local variable making
    // syntax shorter and access faster.
    var $P = Date.prototype;

    // Old
    // Date.prototype.clearTime = function() {

    // New
    $P.clearTime = function () {
        return this;

After changing everything over we were able to shave a little over 1k off the total library size and our performance tests did register an improvement. Great advice, and Datejs is now better (and faster!).

All this has been checked into SVN for public consumption.


  1. […] Advice on Datejs compression and performance tuning […]

    Pingback by Advice — January 22, 2008 @ 11:09 pm

  2. clearTime() can be optimised further, as setHours() can take up to 4 arguments.

    Comment by Mathew Robertson — February 16, 2010 @ 8:25 pm

  3. Doesn’t handle leap-seconds, as it is validating that there must be 0-59 seconds. Leap-seconds can have up to 61 seconds per minute.

    Comment by Mathew Robertson — February 16, 2010 @ 8:31 pm

Sorry, the comment form is closed at this time.