the html5 solution to ajax pitfalls on mobile devices

12
The HTML5 Solution to Ajax Pitfalls on Mobile Devices. AT&T Mobile App Hackathon - Atlanta Speaker: Wesley Hales @wesleyhales Saturday, September 10, 2011

Upload: wesleyhales

Post on 25-May-2015

1.555 views

Category:

Technology


2 download

DESCRIPTION

Lightning talk given at the Atlanta AT&T Mobile App Hackathon on 9/10/2011. Blog on topic here: http://community.jboss.org/people/wesleyhales/blog/2011/08/28/fixing-ajax-on-mobile-devices

TRANSCRIPT

Page 1: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

The HTML5 Solution to Ajax Pitfalls on Mobile Devices.AT&T Mobile App Hackathon - AtlantaSpeaker: Wesley Hales@wesleyhales

Saturday, September 10, 2011

Page 2: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

• Senior Developer at Red Hat

• W3C Member

• HTML5 User Group Founder

• html5rocks.com, DZone Refcard, and author of many other articles around the web.

Wesley Hales@wesleyhales

Saturday, September 10, 2011

Page 3: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Saturday, September 10, 2011

Page 4: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

innerHTML()

Saturday, September 10, 2011

Page 5: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Douglas Crockford - Javascript The Good Parts

“If the HTML text contains a <script> tag or its equivalent, then an evil script will run. ..

Saturday, September 10, 2011

Page 6: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Java Mobile Web Settings• Causes browser memory leaks

• You don’t get a reference to the element you just created

• Problems with some elements setting their innerHTML

• And it fails on iOS...

Not only is innerHTML() bad...

Saturday, September 10, 2011

Page 7: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Java Mobile Web Settings

• Stops working randomly

• It’s a 4 year old problem in Safari

• there are hacks to workaround

• setTimeout(‘yuck’)

Beware of innerHTML on

Saturday, September 10, 2011

Page 8: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Java Mobile Web Settings• get the xhr.responseText

• send it to an automatically generated HTML5 sandbox iframe

• pull from the iframe DOM and use document.adoptNode

The Solution

Saturday, September 10, 2011

Page 9: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Java Mobile Web SettingsThe Solutionfunction getFrame() {    var frame = document.getElementById("temp-frame");    if (!frame) {        // create frame        frame = document.createElement("iframe");        frame.setAttribute("id", "temp-frame");        frame.setAttribute("name", "temp-frame");        frame.setAttribute("seamless", "");        frame.setAttribute("sandbox", "");        frame.style.display = 'none';        document.documentElement.appendChild(frame);    }    return frame.contentDocument;}

Saturday, September 10, 2011

Page 10: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Java Mobile Web SettingsThe Solution

var frame = getFrame();frame.write(responseText);

Saturday, September 10, 2011

Page 11: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Java Mobile Web SettingsThe Solution

document.getElementById(elementId).appendChild(document.adoptNode(incomingElements));

Saturday, September 10, 2011

Page 12: The HTML5 Solution to Ajax Pitfalls on Mobile Devices

Mobile Web Apps Live (or DIE) by the UIQuestions?

Saturday, September 10, 2011