PhoneGap core contributor
works for Graphite Software
nutty about speech recognition
Did you know that mobile browsers will wait 300ms from the time that you tap the button to fire the click event.
The reason for this is that the browser is waiting to see if you are actually performing a double tap.
FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers. The aim is to make your application feel less laggy and more responsive while avoiding any interference with your current logic.
Normal: 21.8 kb
Minified: 13.9 kb
Compressed: 2.2 kb
window.addEventListener('load', function() {
FastClick.attach(document.body);
}, false);
Well maybe not hard but definitely more difficult than they need to be. For instance in order to detect a "swipe left" gesture you'll have to listen to and react to the "touchstart", "touchmove" and "touchend" events.
Hammer supports Tap, DoubleTap, Swipe, Drag, Pinch, and Rotate gestures. Each gesture triggers useful events and eventData.
Normal: 47.2 kb
Minified: 12.5 kb
Compressed: 3.0 kb
Hammer(el).on("swipeleft", function() {
alert('you swiped left!');
});
jQuery is a great cross platorm library but how many of you actually use all of it?
When you are developing a mobile web app do you really need jQuery to smooth over browser inconsistencies when most mobile OS have webkit based browsers?
Normal: 246 kb
Minified: 86 kb
Compressed: 29.2 kb
// jQuery
var n = $("article#first p.summary");
// JavaScript
var n = document.querySelectorAll("article#first p.summary");
// jQuery
$("#container").append("more content
");
// JavaScript
document.getElementById("container").innerHTML += "more content
";
// jQuery
$('body').addClass('hasJS');
$('body').removeClass('hasJS');
// JavaScript
document.body.classList.add('hasJS');
document.body.classList.remove('hasJS');
// jQuery
$('#somelink').on('touchstart', handleTouch);
// JavaScript
var el = document.getElementById('somelink');
el.addEventListener("touchstart", handleTouch);
If you only ever use jQuery for DOM selection consider replacing it with:
var $ = document.querySelectorAll.bind(document);
You may also want to take a look at Remy Sharp's min.js which provides a jQuery syntax for query selection and events.