Skip to content
This repository

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

Open
wants to merge 1 commit into from

2 participants

wangshijun Marcel Duran
wangshijun

Added dom ready time as "rt", make page load time more accurate.

Marcel Duran
Owner

could you please double check where else t_done is used? I'm afraid other "flavors" of YSlow might use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 04, 2013
wangshijun wangshijun Add dom ready time, more accurate load time aff3897
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 29 additions and 6 deletions. Show diff stats Hide diff stats

  1. +7 4 src/common/util.js
  2. +22 2 src/phantomjs/controller.js
11 src/common/util.js
@@ -251,7 +251,7 @@ YSLOW.util = {
251 251
252 252 /**
253 253 * Returns the hostname (domain) for a given URL
254   - *
  254 + *
255 255 * @param {String} url The absolute URL to get hostname from
256 256 * @return {String} The hostname
257 257 */
@@ -845,8 +845,11 @@ YSLOW.util = {
845 845 params.s = encodeURI(spaceid);
846 846 }
847 847 params.i = yscontext.result_set.getRulesetApplied().id;
848   - if (yscontext.PAGE.t_done) {
849   - params.lt = parseInt(yscontext.PAGE.t_done, 10);
  848 + if (yscontext.PAGE.t_ready) {
  849 + params.rt = parseInt(yscontext.PAGE.t_ready, 10);
  850 + }
  851 + if (yscontext.PAGE.t_load) {
  852 + params.lt = parseInt(yscontext.PAGE.t_load, 10);
850 853 }
851 854
852 855 if (include_grade) {
@@ -1889,7 +1892,7 @@ YSLOW.util = {
1889 1892
1890 1893 /**
1891 1894 * identifies injected elements (js, css, iframe, flash, image)
1892   - * @param doc the document to create/manipulate dom elements
  1895 + * @param doc the document to create/manipulate dom elements
1893 1896 * @param comps the component set components
1894 1897 * @param body the root (raw) document body (html)
1895 1898 * @return the same components with injected info
24 src/phantomjs/controller.js
@@ -165,6 +165,17 @@ urls.forEach(function (url) {
165 165 }
166 166 };
167 167
  168 + // timingStartTime, timingDOMContentLoaded
  169 + // https://groups.google.com/forum/?fromgroups=#!topic/phantomjs/WnXZLIb_jVc
  170 + page.onInitialized = function () {
  171 + page.timingStartTime = page.evaluate(function () {
  172 + (function () {
  173 + document.addEventListener("DOMContentLoaded", function(){window.timingDOMContentLoaded = Date.now();}, false);
  174 + })();
  175 + return Date.now();
  176 + });
  177 + };
  178 +
168 179 // enable console output, useful for debugging
169 180 yslowArgs.console = parseInt(yslowArgs.console, 10) || 0;
170 181 if (yslowArgs.console) {
@@ -232,7 +243,14 @@ urls.forEach(function (url) {
232 243 console.log('FAIL to load ' + url);
233 244 } else {
234 245 // page load time
235   - loadTime = new Date() - startTime;
  246 + loadTime = new Date() - page.timingStartTime;
  247 +
  248 + // timingDOMContentLoaded
  249 + // https://groups.google.com/forum/?fromgroups=#!topic/phantomjs/WnXZLIb_jVc
  250 + page.timingDOMContentLoaded = JSON.parse(page.evaluate(function () {
  251 + return window.timingDOMContentLoaded;
  252 + }));
  253 + page.readyTime = page.timingDOMContentLoaded - page.timingStartTime;
236 254
237 255 // set resources response time
238 256 for (url in resources) {
@@ -254,6 +272,7 @@ urls.forEach(function (url) {
254 272 ysphantomjs = 'YSLOW.phantomjs = {' +
255 273 'resources: ' + JSON.stringify(resources) + ',' +
256 274 'args: ' + JSON.stringify(yslowArgs) + ',' +
  275 + 'readyTime: ' + JSON.stringify(page.readyTime) + ',' +
257 276 'loadTime: ' + JSON.stringify(loadTime) + '};';
258 277
259 278 // YSlow phantomjs controller
@@ -370,7 +389,8 @@ urls.forEach(function (url) {
370 389 yscontext.component_set = cset;
371 390 ys.controller.lint(doc, yscontext, args.ruleset);
372 391 yscontext.result_set.url = baseHref;
373   - yscontext.PAGE.t_done = ysphantomjs.loadTime;
  392 + yscontext.PAGE.t_load = ysphantomjs.loadTime;
  393 + yscontext.PAGE.t_ready = ysphantomjs.readyTime;
374 394 yscontext.collectStats();
375 395 results = ysutil.getResults(yscontext, args.info);
376 396

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.