YSlow.js on Node.js is a simple Node.js wrapper for programmatically running phantomjs yslow.js
.
PATH
.$ npm install yslowjs
See Phapper if you're having issues with PhantomJS.
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.
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!
// 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); } });
// 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);
yslow.js
Downloadvar YSlow = require('lib/yslow'); YSlow.prototype.script = '/path/to/your/yslow.js'; // continue on
Copyright (c) 2015 Joshua Mervine
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run
. Now passes both error
and results
to callback. See README examples for details. This update is not backwards compatabile with previous releases.
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.