Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 3.33 KB

README.md

File metadata and controls

89 lines (64 loc) · 3.33 KB

YSlow.js on Node.js

Build Status   Dependancy Status   NPM Version   <iframe src="http://jmervine.github.io/npm-downloads-badge/badge.html?module=yslowjs&name=false" allowtransparency="true" frameborder="0" scrolling="0" width="125" height="20" style="vertical-align: bottom"></iframe>

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

:::shell
$ 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.

Configuration Options

:::js
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

:::js
// 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

:::js
// 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

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