Use JQuery Mobile’s Tools Suite to help you debug and improve your JQuery Mobile application
If you’ve worked on a JQuery Mobile project that contains any significant amount of complexity, you will inevitably run across many occasions where you want to scream at the top of your lungs one or more of the following:
• “What is going on!”
• “Why isn’t this working!”
Typically you (hopefully) dig through the JQuery Mobile documentation, and even the source code (right?) to try and piece together what is going on, and perhaps you try and step your way through a debugger session full of various functions, events, callbacks, and so on. Or perhaps you simply throw up your arms and post your issue on Stack Overflow or JQuery Mobile’s forums. All of these options contain varying degrees of validity and usefulness – so don’t let me stop you from doing any/all of these things, but I believe many developers are not aware of an additional resource that is at your disposal – a set of debug pages and scripts within JQuery Mobile itself. In many instances, these tools can save you significant time and effort on the sleuthing trail. So let’s look at them already!
We have 3 main “out of the box” tools at our disposal, which I’ll cover in sections, but here’s a list of what we’ll cover so you can optionally skip to a particular section you might be especially interested in:
These tools can be found here, under the JQuery Mobile git repository, which I would encourage you to clone if you wish to use JQuery Mobile and/or the tools referenced in this article. While the tools in their ‘out of the box’ state can be rather useful (as I’ll try and show), you may find that you can get even more out of them by customizing their output. You may even decide to add your own tools, and hopefully contribute them back to the project if you believe others would find them useful! So pull down the code, and use the overview below as your primer to look into the files/scripts referenced to see what exactly they are doing.
The ‘Configuration Properties tool is an html page (config-props.html) which dumps out the values within JQuery Mobile’s $.mobile and $.support objects. Discussion of these values can be found on JQuery Mobile’s website here , so please leverage this documentation to become familiar with when these values can be set and ensuring that you are viewing this page after they have been set and JQuery Mobile has been initialized. These global config objects contain properties that are at the core of how JQuery Mobile gets configured to function for a particular user’s environment, and you should become familiar with these properties and their various possible values to understand how your JQuery Mobile app can be made to function differently when it is setup with different global config property values. An example default output from JQuery Mobile 1.2 (final) for these settings is shown below:
As mentioned above, when you change from one JQuery Mobile page to another, typically either through clicking on a link to another JQuery Mobile page that already exists in the DOM, or by manually calling $.mobile.changePage, several events and subsequent actions occur. At a high level the following actions occur:
• A page change process is begun
• A new page is loaded
• The content for that page is “enhanced” (styled)
• A transition (slide/pop/etc) from the existing page to the new page occurs
The ‘Page Change Times’ tool gives you a breakdown for how long each part of this “changePage” process takes. An example output is shown below.
load + processing: 3
These values are in milliseconds.
One thing I do not like about the script (page-change-time.js) is that it outputs these times in an alert box, so each “change page” is going to show you this data by halting the app. If this also bugs you, you should feel free to alter this script for your own use case, to probably output these values to the console instead.
JQuery Mobile provides a set of 3 “out of the box” scripts to help you gain insight and understanding into current global configuration values, page events, and page change timings in your application. Using these scripts as part of your development process should provide you insight into what is happening “under the covers” in your application, reducing frustration and increasing your understanding of how your application functions. I encourage you to give these scripts a try, and customize them as you see fit to help you increase the efficiency of your development efforts.