Skip to content

Commit b8dcdc9

Browse files
committed
A simple bookmarklet that allows us to attach to a jQuery Mobile application and throw an alert that displays the load, enhancment, and transition times for a page the user navigates to.
1 parent ee779f2 commit b8dcdc9

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

tools/page-change-time.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Page Change Timer Bookmarklet</title>
7+
</head>
8+
9+
<body>
10+
<h1>Page Event Logger Bookmarklet</h1>
11+
<p>A simple bookmarklet for timing the load, enhanement, and transition of a jQuery Mobile changePage() request. To use, bookmark the following link:</p>
12+
<script>
13+
document.write('<p><a id="bookmarklet-link" href="javascript:function loadScript(u){var s=document.createElement(\'script\');s.setAttribute(\'language\',\'javascript\');s.setAttribute(\'src\',u);document.body.appendChild(s);} loadScript(\'' + ( location.href.replace( /\.html/, ".js" ) ) + '\');">Page Change Timing Bookmark</a></p>');
14+
</script>
15+
<p>For platforms that don't allow bookmarking of <code>javascript:</code> urls, you can copy/paste the following source for the bookmarklet directly into the browser's location bar then hit enter or hit the &quot;go&quot; button on your keypad:</p>
16+
<p>
17+
<textarea id="ta" rows="10" cols="50"></textarea>
18+
</p>
19+
<p>NOTE: Some browsers like Chrome will strip off the javascript: prefix from the string above when you paste it into the location bar. Make sure what you pasted is prefixed by javascript: before attempting to load the bookmarklet.</p>
20+
<script>
21+
document.getElementById("ta").value = document.getElementById("bookmarklet-link").href;
22+
</script>
23+
</body>
24+
</html>

tools/page-change-time.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*!
2+
* jQuery Mobile v@VERSION
3+
* http://jquerymobile.com/
4+
*
5+
* Copyright 2011, jQuery Project
6+
* Dual licensed under the MIT or GPL Version 2 licenses.
7+
* http://jquery.org/license
8+
*/
9+
10+
// This is code that can be used as a simple bookmarklet for timing
11+
// the load, enhancment, and transition of a changePage() request.
12+
13+
(function( $, window, undefined ) {
14+
15+
16+
function getTime() {
17+
return ( new Date() ).getTime();
18+
}
19+
20+
var startChange, stopChange, startLoad, stopLoad, startEnhance, stopEnhance, startTransition, stopTransition, lock = 0;
21+
22+
$( document )
23+
.bind( "pagebeforechange", function( e, data) {
24+
if ( typeof data.toPage === "string" ) {
25+
startChange = stopChange = startLoad = stopLoad = startEnhance = stopEnhance = startTransition = stopTransition = getTime();
26+
}
27+
})
28+
.bind( "pagebeforeload", function() {
29+
startLoad = stopLoad = getTime();
30+
})
31+
.bind( "pagebeforecreate", function() {
32+
if ( ++lock === 1 ) {
33+
stopLoad = startEnhance = stopEnhance = getTime();
34+
}
35+
})
36+
.bind( "pageinit", function() {
37+
if ( --lock === 0 ) {
38+
stopEnhance = getTime();
39+
}
40+
})
41+
.bind( "pagebeforeshow", function() {
42+
startTransition = stopTransition = getTime();
43+
})
44+
.bind( "pageshow", function() {
45+
stopTransition = getTime();
46+
})
47+
.bind( "pagechange", function( e, data ) {
48+
if ( typeof data.toPage === "object" ) {
49+
stopChange = getTime();
50+
51+
alert("load + processing: " + ( stopLoad - startLoad )
52+
+ "\nenhance: " + ( stopEnhance - startEnhance )
53+
+ "\ntransition: " + ( stopTransition - startTransition )
54+
+ "\ntotalTime: " + ( stopChange - startChange ) );
55+
56+
startChange = stopChange = startLoad = stopLoad = startEnhance = stopEnhance = startTransition = stopTransition = 0;
57+
}
58+
});
59+
60+
61+
})( jQuery, window );

0 commit comments

Comments
 (0)