I have a largish app which in one place contains something like this. It's created by the Intel XDK New's ui builder.
<div class="table-thing with-label widget uib_w_11 team-margins-2" data-uib="jquery_mobile/select" data-ver="0">
<label class="narrow-control">Choose region:</label>
<div data-role="fieldgroup" class+="" "wide-control"="">
<select autofocus="" data-native-menu="true" id="region-id" data-mini="true">
<option value="1">One</option>
<option value="2">Two</option>
/select>
</div>
</div>
<div class="table-thing with-label widget uib_w_11 team-margins-2" data-uib="jquery_mobile/select" data-ver="0">
<label class="narrow-control">Choose club:</label>
<div data-role="fieldgroup" class+="" "wide-control"="">
<select autofocus="" data-native-menu="true" id="club-id" data-mini="true">
/select>
</div>
</div>
I have an event handler on region-id like this. (Also one on club-id for other reasons.)
var $select = $('#region-id');
$select.unbind('change');
$select.bind('change', function (event) {
event.stopPropagation();
event.preventDefault();
var value = $select.find(':selected').val();
... insert <option> HTML into #club-id here
... with and without $select.selectmenu("refresh")
});
The change event triggers about 2 seconds after a choice is made on region-id on a Samsung Galaxy S4. Such a delay is problematic. The delay on the Samsung Tab2 is not noticeable.
- I've put tap and vclick event handlers on region-id and they trigger about 1.5-2 secs before change does. (Timing done with window.performance.now)
- The change event handler is more extensive that that illustrated but it completes in less than .1 sec.
- I've dumped $('club-id').html() at the end of the handler and its the same as the HTML when club-id is finally rendered.
- FWIW, $.mobile.buttonMarkup.hoverDelay = 0 doesn't help.
So I conclude there is a built-in 1.5-2sec delay built-in on at least this phone.
This seems similar to 0.5 sec delays on click events for buttons, workarounds for which are easily found:fastclick and Google fast buttons
However these don't work for click on a select option. The only relevant query I've found is this one on stackoverflow. There the questioner avoided the issue by opting for jqm's custom method with
data-native-menu="false"
I can't do this as it causes other issues which break my app.
So ... any suggestions on how to reduce the 2 sec delay on select's change trigger?
EDIT: MORE INFO
I followed up on Gavin Lloyd's suggestions, converted to non-jQuery handlers and added some event handlers:
$select[0].addEventListener('touchstart', function (event) {
UTIL.consoleLog('touchstart event', UTIL.performanceNow());
var value = $select.find(':selected').val();
UTIL.consoleLog('value=', value);
});
$select[0].addEventListener('touchend', function (event) {
UTIL.consoleLog('touchend event', UTIL.performanceNow());
var value = $select.find(':selected').val();
UTIL.consoleLog('value=', value);
});
$select[0].addEventListener('change', function (event) {
UTIL.consoleLog('change event', UTIL.performanceNow());
...
});
The timings were:
5378 touchstart (tap dropdown button)
5471 touchend (end tap dropdown)
... say 0.25 sec to tap an option (no way to time this)
6539 change event
6543 start updating select tags
6558 end updating: do $select.selectmenu('refresh', true) and confirm $select.html() exists
So the DOM is updated 6558-5471-250 = .837 sec after the option is selected. This is reasonable. However the DOM is visually updated between 2-2.5 secs after the option is selected. This suggests much of the delay occurs after the HTML is updated
I rolled the CSS using the jqm themeroller and its not small'ish. I removed themes B&C leaving just A. (So 1/3 the original size.) This did not seem to affect the results.
I would not expect jqm to 'reload' the page or do anything else radical.
Any suggestions by jqm + phonegap are so slow repainting the DOM ?