YSlow.js on Node.js

Build Status   Dependancy Status   NPM Version  

YSlow.js on Node.js is a simple Node.js wrapper for programmatically running phantomjs yslow.js.

Links

Requirements

  1. PhantomJS in your PATH.
  2. Tested on the following node versions (via Travis-ci.org):
    • 0.8
    • 0.10

Installation

$ npm install yslowjs

See Phapper if you're having issues with PhantomJS.

Additional Installation Notes

You can specify different versions of YSlow.js using npm config:

$ npm config set yslowjs_version

You will have to reinstall yslowjs if you change this option after initially installing it.

Windows? Click here!

Configuration Options

var yslow = new YSlow('http://example.com/path/foo',
    [ '--arg', 'value' ]);
    // Supported:
    //   info     specify the information to display/log (basic|grade|stats|comps|all) [all],
    //   ruleset  specify the YSlow performance ruleset to be used (ydefault|yslow1|yblog) [ydefault],
    //   beacon   specify an URL to log the results,
    //   ua       specify the user agent string sent to server when the page requests resources,
    //   viewport specify page viewport size WxY, where W = width and H = height [400x300],
    //   headers  specify custom request headers, e.g.: -ch '{\'Cookie\': \'foo=bar\'}',
    // WARNING: format is locked at json, so don't pass it!

Usage Examples

Async

// file: async.js
var YSlow = require('lib/yslow');
var yslow = new YSlow('http://mervine.net/projects/npms/yslowjs',
    [ '--info', 'basic' ]);
console.log('\nRunning (Async)....');
yslow.run( function (error, result) {
    if (error) {
        console.trace(error);
    } else {
        console.log('=> overall:   ' + result.o);
        console.log('=> load time: ' + result.lt);
    }
});

Sync

// file: sync.js
var YSlow = require('lib/yslow');
var yslow = new YSlow('http://mervine.net/projects/npms/yslowjs',
    [ '--info', 'basic' ]);
console.log('\nRunning (Sync)....');
var results = yslow.runSync();
console.log('=> overall:   ' + results.o);
console.log('=> load time: ' + results.lt);

Using Custom yslow.js Download

var YSlow = require('lib/yslow');
YSlow.prototype.script = '/path/to/your/yslow.js';
// continue on

Articles on YSlow.js on Node.js

YSlow.js: Release 0.3.1

Links: readme | package | source | tests

0.3.2

Previous Version

  • 0.3.1
  • 0.3.0
    • Fixing error handling in run. Now passes both error and results to callback. See README examples for details. This update is not backwards compatabile with previous releases.
  • 0.2.1
    • Removing unused dependainces.
  • 0.2.0
    • Top down refactor using updated Phapper.
    • Includes better pathing support for finding included yslow.js.
    • Downloads and install yslow.js if it can't be found, which should never happen.
    • Adding limited support for Windows.
  • 0.1.2
    • Fixing critical issue in NODE_PATH search when working with global installations.
  • 0.1.1
    • Refactored to use Phapper, way cleaner and less code.
    • Refactored tests for change to Phapper.
    • Refactored stubs..
    • Adding functional tests.
  • 0.0.1
    • Initial release.

Benchmarking with YSlow.js on Node.js

In my last post on this topic (Benchmarking with HTTPerf.js and NodeUnit) I covered benchmarking application render times from the server to first byte. In this post, I'm going cover basic client benchmarking using YSlow and PhantomJS via YSlow.js on Node.js.

Continue reading