Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phantomjs: add dom ready timing, more accurate page load timing #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/common/util.js
Expand Up @@ -251,7 +251,7 @@ YSLOW.util = {


/** /**
* Returns the hostname (domain) for a given URL * Returns the hostname (domain) for a given URL
* *
* @param {String} url The absolute URL to get hostname from * @param {String} url The absolute URL to get hostname from
* @return {String} The hostname * @return {String} The hostname
*/ */
Expand Down Expand Up @@ -845,8 +845,11 @@ YSLOW.util = {
params.s = encodeURI(spaceid); params.s = encodeURI(spaceid);
} }
params.i = yscontext.result_set.getRulesetApplied().id; params.i = yscontext.result_set.getRulesetApplied().id;
if (yscontext.PAGE.t_done) { if (yscontext.PAGE.t_ready) {
params.lt = parseInt(yscontext.PAGE.t_done, 10); params.rt = parseInt(yscontext.PAGE.t_ready, 10);
}
if (yscontext.PAGE.t_load) {
params.lt = parseInt(yscontext.PAGE.t_load, 10);
} }


if (include_grade) { if (include_grade) {
Expand Down Expand Up @@ -1889,7 +1892,7 @@ YSLOW.util = {


/** /**
* identifies injected elements (js, css, iframe, flash, image) * 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 comps the component set components
* @param body the root (raw) document body (html) * @param body the root (raw) document body (html)
* @return the same components with injected info * @return the same components with injected info
Expand Down
24 changes: 22 additions & 2 deletions src/phantomjs/controller.js
Expand Up @@ -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 // enable console output, useful for debugging
yslowArgs.console = parseInt(yslowArgs.console, 10) || 0; yslowArgs.console = parseInt(yslowArgs.console, 10) || 0;
if (yslowArgs.console) { if (yslowArgs.console) {
Expand Down Expand Up @@ -232,7 +243,14 @@ urls.forEach(function (url) {
console.log('FAIL to load ' + url); console.log('FAIL to load ' + url);
} else { } else {
// page load time // 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 // set resources response time
for (url in resources) { for (url in resources) {
Expand All @@ -254,6 +272,7 @@ urls.forEach(function (url) {
ysphantomjs = 'YSLOW.phantomjs = {' + ysphantomjs = 'YSLOW.phantomjs = {' +
'resources: ' + JSON.stringify(resources) + ',' + 'resources: ' + JSON.stringify(resources) + ',' +
'args: ' + JSON.stringify(yslowArgs) + ',' + 'args: ' + JSON.stringify(yslowArgs) + ',' +
'readyTime: ' + JSON.stringify(page.readyTime) + ',' +
'loadTime: ' + JSON.stringify(loadTime) + '};'; 'loadTime: ' + JSON.stringify(loadTime) + '};';


// YSlow phantomjs controller // YSlow phantomjs controller
Expand Down Expand Up @@ -370,7 +389,8 @@ urls.forEach(function (url) {
yscontext.component_set = cset; yscontext.component_set = cset;
ys.controller.lint(doc, yscontext, args.ruleset); ys.controller.lint(doc, yscontext, args.ruleset);
yscontext.result_set.url = baseHref; 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(); yscontext.collectStats();
results = ysutil.getResults(yscontext, args.info); results = ysutil.getResults(yscontext, args.info);


Expand Down