Skip to content

Instantly share code, notes, and snippets.

@acdha
Created June 27, 2013 19:54
Show Gist options
  • Select an option

  • Save acdha/5879798 to your computer and use it in GitHub Desktop.

Select an option

Save acdha/5879798 to your computer and use it in GitHub Desktop.
Simple phantomjs script to reload a webpage as quickly as possible: `phantomjs --disk-cache=yes hammer-url.js http://127.0.0.1/path-to-page 500`
/* global phantom, WebPage, require, console */
// jshint strict:false
var system = require('system');
if (system.args.length > 3 || system.args.length < 2) {
console.log('Usage:', system.args[0], 'URL [count=20]');
phantom.exit();
}
var count = parseInt(system.args[2], 10) || 20,
url = system.args[1].trim();
console.log("Loading", url, count, "times");
var page = new WebPage(),
loadStart;
page.onError = function(msg, trace) {
console.log('ERROR:', msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
});
};
page.onConsoleMessage = function() {
console.log.apply(console, arguments);
};
function pageCallback(status) {
if (status !== 'success') {
console.log('Unable to load ', url, ':', status);
} else {
console.log('Loaded', url, 'in', ((Date.now() - loadStart) / 1000).toFixed(1), 'seconds');
}
if (count-- > 0) {
loadNext();
} else {
phantom.exit();
}
}
function loadNext() {
loadStart = Date.now();
page.open(url, pageCallback);
}
loadNext();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment