{"id":244,"date":"2013-07-30T14:44:45","date_gmt":"2013-07-30T14:44:45","guid":{"rendered":"https:\/\/gosqeng.test\/?p=244"},"modified":"2019-11-28T12:31:40","modified_gmt":"2019-11-28T12:31:40","slug":"touchstart-events","status":"publish","type":"post","link":"https:\/\/www.gosquared.com\/blog\/touchstart-events","title":{"rendered":"Making mobile web apps feel faster"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/\/static.gosquared.com\/images\/engineering\/13_07_30_touchstart_01.png\" alt=\"The new GoSquared Analytics Dashboard running on iOS on iPhone 5 - responsive design with touchstart events in action\"\/><\/p>\n<p>Interacting with mobile web apps often feels sluggish and slow, but our phones are more than capable of handing the applications.<\/p>\n<p>When you touch a button, you expect it to perform its action immediately. However, a <code>click<\/code> event listener will only trigger when the touch finishes (<code>touchend<\/code>), rather than when it begins (<code>touchstart<\/code>). This delays every action unnecessarily.<\/p>\n<h2>TouchStart to the rescue<\/h2>\n<p>The easy solution, then, is to bind all your click events to <code>touchstart<\/code> too.<\/p>\n<p>Oops, we&#8217;ve just made every event trigger twice on touch devices. The solution is also simple, storing a property on the event object to check if it&#8217;s already been triggered. Luckily, the event object is the same across both triggers, otherwise things would be a lot more difficult.<\/p>\n<h2>Quick Example<\/h2>\n<h3>Old code<\/h3>\n<p>&nbsp;<\/p>\n<pre>$('.my-button').on('click', function(e) {\n    doSomething();\n});<\/pre>\n<p>&nbsp;<\/p>\n<h3>New Code<\/h3>\n<p>&nbsp;<\/p>\n<pre>$('.my-button').on('click touchstart', function(e) {\n    if (e.handled) return;\n\n    e.handled = true;\n    doSomething();\n});<\/pre>\n<p>&nbsp;<\/p>\n<h2>Summary<\/h2>\n<p>Easy, right? At GoSquared we&#8217;ve made sure we use this solution in as many places as possible, especially our new menubar in GoSquared Beta. <a href=\"https:\/\/docs.google.com\/forms\/d\/1W0C_AXiURizZELDG0RJlqAX02NcKUzY8oQp6npc1-Bc\/viewform\">Apply for early access<\/a>!<\/p>\n<p><small>Note: don&#8217;t add the <code>touchstart<\/code> listener to very important buttons, such as account settings, as if the user starts scrolling down with their finger over the button, it&#8217;ll trigger when they don&#8217;t expect it.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"\/\/static.gosquared.com\/images\/engineering\/13_07_30_touchstart_01.png\" alt=\"The new GoSquared Analytics Dashboard running on iOS on iPhone 5 - responsive design with touchstart events in action\"\/><\/p>\n<p>Interacting with mobile web apps often feels sluggish and slow, but our phones are more than capable of handing the applications.<\/p>\n<p>When you touch a button, you expect it to perform its action immediately. However, a <code>click<\/code> event listener will only trigger when the touch finishes (<code>touchend<\/code>), rather than when it begins (<code>touchstart<\/code>). This delays every action unnecessarily.<\/p>\n<p>Here&#8217;s how to make your mobile web app feel faster and more snappy, all with just a couple of lines of code.<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1452],"tags":[107,1159,617],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-engineering","tag-apps","tag-events","tag-mobile"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.6 (Yoast SEO v19.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Speed up Mobile Web Apps with TouchStart events- GoSquared Engineering<\/title>\n<meta name=\"description\" content=\"Using the touchstart events instead of just a click handler can help make your mobile web application feel fast and snappy. It&#039;s easy - here&#039;s how to do it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.gosquared.com\/blog\/touchstart-events\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Making mobile web apps feel faster\" \/>\n<meta property=\"og:description\" content=\"Using the touchstart events instead of just a click handler can help make your mobile web application feel fast and snappy. It&#039;s easy - here&#039;s how to do it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.gosquared.com\/blog\/touchstart-events\" \/>\n<meta property=\"og:site_name\" content=\"GoSquared Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GoSquared\" \/>\n<meta property=\"article:published_time\" content=\"2013-07-30T14:44:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-28T12:31:40+00:00\" \/>\n<meta property=\"og:image\" content=\"\/\/static.gosquared.com\/images\/engineering\/13_07_30_touchstart_01.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@simon_tabor\" \/>\n<meta name=\"twitter:site\" content=\"@GoSquared\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Simon Tabor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\",\"name\":\"GoSquared\",\"url\":\"https:\/\/www.gosquared.com\/blog\/\",\"sameAs\":[\"https:\/\/instagram.com\/gosquaredteam\",\"https:\/\/www.linkedin.com\/company\/go-squared-ltd.\",\"https:\/\/www.facebook.com\/GoSquared\",\"https:\/\/twitter.com\/GoSquared\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png\",\"contentUrl\":\"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png\",\"width\":1270,\"height\":250,\"caption\":\"GoSquared\"},\"image\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#website\",\"url\":\"https:\/\/www.gosquared.com\/blog\/\",\"name\":\"GoSquared Blog\",\"description\":\"Turn visitors into customers.\",\"publisher\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.gosquared.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events#webpage\",\"url\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events\",\"name\":\"Speed up Mobile Web Apps with TouchStart events- GoSquared Engineering\",\"isPartOf\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#website\"},\"datePublished\":\"2013-07-30T14:44:45+00:00\",\"dateModified\":\"2019-11-28T12:31:40+00:00\",\"description\":\"Using the touchstart events instead of just a click handler can help make your mobile web application feel fast and snappy. It's easy - here's how to do it.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.gosquared.com\/blog\/touchstart-events\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.gosquared.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Making mobile web apps feel faster\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events#webpage\"},\"author\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/71fad71f60ad33cf9356687b37aed3d0\"},\"headline\":\"Making mobile web apps feel faster\",\"datePublished\":\"2013-07-30T14:44:45+00:00\",\"dateModified\":\"2019-11-28T12:31:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/touchstart-events#webpage\"},\"wordCount\":198,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\"},\"keywords\":[\"Apps\",\"Events\",\"Mobile\"],\"articleSection\":[\"Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.gosquared.com\/blog\/touchstart-events#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/71fad71f60ad33cf9356687b37aed3d0\",\"name\":\"Simon Tabor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dc920e48608646bda51d2e6e2595e8ad926cff52eba534c1d25fb1618f15b59f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dc920e48608646bda51d2e6e2595e8ad926cff52eba534c1d25fb1618f15b59f?s=96&d=mm&r=g\",\"caption\":\"Simon Tabor\"},\"description\":\"Lead developer at GoSquared for integrations, partnerships and the API. Works on pretty much everything.\",\"sameAs\":[\"http:\/\/simontabor.com\",\"https:\/\/twitter.com\/simon_tabor\"],\"url\":\"https:\/\/www.gosquared.com\/blog\/author\/simontabor\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Speed up Mobile Web Apps with TouchStart events- GoSquared Engineering","description":"Using the touchstart events instead of just a click handler can help make your mobile web application feel fast and snappy. It's easy - here's how to do it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.gosquared.com\/blog\/touchstart-events","og_locale":"en_US","og_type":"article","og_title":"Making mobile web apps feel faster","og_description":"Using the touchstart events instead of just a click handler can help make your mobile web application feel fast and snappy. It's easy - here's how to do it.","og_url":"https:\/\/www.gosquared.com\/blog\/touchstart-events","og_site_name":"GoSquared Blog","article_publisher":"https:\/\/www.facebook.com\/GoSquared","article_published_time":"2013-07-30T14:44:45+00:00","article_modified_time":"2019-11-28T12:31:40+00:00","og_image":[{"url":"\/\/static.gosquared.com\/images\/engineering\/13_07_30_touchstart_01.png"}],"twitter_card":"summary_large_image","twitter_creator":"@simon_tabor","twitter_site":"@GoSquared","twitter_misc":{"Written by":"Simon Tabor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.gosquared.com\/blog\/#organization","name":"GoSquared","url":"https:\/\/www.gosquared.com\/blog\/","sameAs":["https:\/\/instagram.com\/gosquaredteam","https:\/\/www.linkedin.com\/company\/go-squared-ltd.","https:\/\/www.facebook.com\/GoSquared","https:\/\/twitter.com\/GoSquared"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png","contentUrl":"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png","width":1270,"height":250,"caption":"GoSquared"},"image":{"@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/www.gosquared.com\/blog\/#website","url":"https:\/\/www.gosquared.com\/blog\/","name":"GoSquared Blog","description":"Turn visitors into customers.","publisher":{"@id":"https:\/\/www.gosquared.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.gosquared.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.gosquared.com\/blog\/touchstart-events#webpage","url":"https:\/\/www.gosquared.com\/blog\/touchstart-events","name":"Speed up Mobile Web Apps with TouchStart events- GoSquared Engineering","isPartOf":{"@id":"https:\/\/www.gosquared.com\/blog\/#website"},"datePublished":"2013-07-30T14:44:45+00:00","dateModified":"2019-11-28T12:31:40+00:00","description":"Using the touchstart events instead of just a click handler can help make your mobile web application feel fast and snappy. It's easy - here's how to do it.","breadcrumb":{"@id":"https:\/\/www.gosquared.com\/blog\/touchstart-events#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.gosquared.com\/blog\/touchstart-events"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.gosquared.com\/blog\/touchstart-events#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.gosquared.com\/blog"},{"@type":"ListItem","position":2,"name":"Making mobile web apps feel faster"}]},{"@type":"Article","@id":"https:\/\/www.gosquared.com\/blog\/touchstart-events#article","isPartOf":{"@id":"https:\/\/www.gosquared.com\/blog\/touchstart-events#webpage"},"author":{"@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/71fad71f60ad33cf9356687b37aed3d0"},"headline":"Making mobile web apps feel faster","datePublished":"2013-07-30T14:44:45+00:00","dateModified":"2019-11-28T12:31:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.gosquared.com\/blog\/touchstart-events#webpage"},"wordCount":198,"commentCount":3,"publisher":{"@id":"https:\/\/www.gosquared.com\/blog\/#organization"},"keywords":["Apps","Events","Mobile"],"articleSection":["Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.gosquared.com\/blog\/touchstart-events#respond"]}]},{"@type":"Person","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/71fad71f60ad33cf9356687b37aed3d0","name":"Simon Tabor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dc920e48608646bda51d2e6e2595e8ad926cff52eba534c1d25fb1618f15b59f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc920e48608646bda51d2e6e2595e8ad926cff52eba534c1d25fb1618f15b59f?s=96&d=mm&r=g","caption":"Simon Tabor"},"description":"Lead developer at GoSquared for integrations, partnerships and the API. Works on pretty much everything.","sameAs":["http:\/\/simontabor.com","https:\/\/twitter.com\/simon_tabor"],"url":"https:\/\/www.gosquared.com\/blog\/author\/simontabor"}]}},"wps_subtitle":"Using TouchStart events for speed","_links":{"self":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":0,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}