Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created October 30, 2012 17:03
Show Gist options
  • Save gabrielschulhof/3981552 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/3981552 to your computer and use it in GitHub Desktop.
diff --git a/docs/_assets/js/jqm-docs.js b/docs/_assets/js/jqm-docs.js
index 91474cc..4589711 100644
--- a/docs/_assets/js/jqm-docs.js
+++ b/docs/_assets/js/jqm-docs.js
@@ -73,3 +73,25 @@ if ( location.protocol.substr(0,4) === 'file' ||
});
});
}
+
+// Measure the time that passes from pageload until pageshow
+// NB: lists-performance.html should load without a transition to avoid having
+// the transition's duration included in the measurement
+$( document ).bind( "pageload", function( e, data ) {
+ var ar = data.dataUrl.split( "/" ), then;
+
+ // If we're loading "lists-performance.html ..."
+ if ( ar.length && ar[ ar.length - 1 ] === "lists-performance.html" ) {
+ // ... save the event's timestamp, and connect to the page's pagebeforeshow
+ then = new Date();
+ data.page.one( "pageshow", function( e, pbsData ) {
+ // ... then compare the time at pagebeforeshow to the one at pageload
+ var now = new Date(),
+ header = data.page.find( ".ui-header h1:first" );
+ // ... and add/replace a span in the header with the result
+ header
+ .remove( "span:jqmData(role='perfData')" )
+ .append( "<span data-" + $.mobile.ns + "role='perfData'> (pageload -> pageshow in " + ( now.getTime() - then.getTime() ) + " ms)</span>" );
+ });
+ }
+});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment