diff --git a/src/common/util.js b/src/common/util.js index d9458ff..155ed56 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -251,7 +251,7 @@ YSLOW.util = { /** * Returns the hostname (domain) for a given URL - * + * * @param {String} url The absolute URL to get hostname from * @return {String} The hostname */ @@ -845,8 +845,11 @@ YSLOW.util = { params.s = encodeURI(spaceid); } params.i = yscontext.result_set.getRulesetApplied().id; - if (yscontext.PAGE.t_done) { - params.lt = parseInt(yscontext.PAGE.t_done, 10); + if (yscontext.PAGE.t_ready) { + params.rt = parseInt(yscontext.PAGE.t_ready, 10); + } + if (yscontext.PAGE.t_load) { + params.lt = parseInt(yscontext.PAGE.t_load, 10); } if (include_grade) { @@ -1889,7 +1892,7 @@ YSLOW.util = { /** * identifies injected elements (js, css, iframe, flash, image) - * @param doc the document to create/manipulate dom elements + * @param doc the document to create/manipulate dom elements * @param comps the component set components * @param body the root (raw) document body (html) * @return the same components with injected info diff --git a/src/phantomjs/controller.js b/src/phantomjs/controller.js index 0360ef7..2ba5ee0 100644 --- a/src/phantomjs/controller.js +++ b/src/phantomjs/controller.js @@ -165,6 +165,17 @@ urls.forEach(function (url) { } }; + // timingStartTime, timingDOMContentLoaded + // https://groups.google.com/forum/?fromgroups=#!topic/phantomjs/WnXZLIb_jVc + page.onInitialized = function () { + page.timingStartTime = page.evaluate(function () { + (function () { + document.addEventListener("DOMContentLoaded", function(){window.timingDOMContentLoaded = Date.now();}, false); + })(); + return Date.now(); + }); + }; + // enable console output, useful for debugging yslowArgs.console = parseInt(yslowArgs.console, 10) || 0; if (yslowArgs.console) { @@ -232,7 +243,14 @@ urls.forEach(function (url) { console.log('FAIL to load ' + url); } else { // page load time - loadTime = new Date() - startTime; + loadTime = new Date() - page.timingStartTime; + + // timingDOMContentLoaded + // https://groups.google.com/forum/?fromgroups=#!topic/phantomjs/WnXZLIb_jVc + page.timingDOMContentLoaded = JSON.parse(page.evaluate(function () { + return window.timingDOMContentLoaded; + })); + page.readyTime = page.timingDOMContentLoaded - page.timingStartTime; // set resources response time for (url in resources) { @@ -254,6 +272,7 @@ urls.forEach(function (url) { ysphantomjs = 'YSLOW.phantomjs = {' + 'resources: ' + JSON.stringify(resources) + ',' + 'args: ' + JSON.stringify(yslowArgs) + ',' + + 'readyTime: ' + JSON.stringify(page.readyTime) + ',' + 'loadTime: ' + JSON.stringify(loadTime) + '};'; // YSlow phantomjs controller @@ -370,7 +389,8 @@ urls.forEach(function (url) { yscontext.component_set = cset; ys.controller.lint(doc, yscontext, args.ruleset); yscontext.result_set.url = baseHref; - yscontext.PAGE.t_done = ysphantomjs.loadTime; + yscontext.PAGE.t_load = ysphantomjs.loadTime; + yscontext.PAGE.t_ready = ysphantomjs.readyTime; yscontext.collectStats(); results = ysutil.getResults(yscontext, args.info);