Permalink
Browse files

Add dom ready time, more accurate load time

  • Loading branch information...
1 parent 1ddc98a commit aff3897176067cf410a174ebdf660dd2ff9d31cd @wangshijun committed Mar 4, 2013
Showing with 29 additions and 6 deletions.
  1. +7 −4 src/common/util.js
  2. +22 −2 src/phantomjs/controller.js
View
@@ -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
@@ -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);

0 comments on commit aff3897

Please sign in to comment.