Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pitfalls and opportuniities of single-page applications, jQuery Conference San Francisco 2012

Pitfalls and opportuniities of single-page applications, jQuery Conference San Francisco 2012

Slides for my "Pitfalls" talk (jQuery Conference 2012). See also https://github.com/jzaefferer/pitfalls-examples

jzaefferer

June 29, 2012
Tweet

More Decks by jzaefferer

Other Decks in Programming

Transcript

  1. “A single-page application (SPA) is a web application or web

    site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application.” --Wikipedia, Single-page application Friday, June 29, 2012
  2. $("a:not([href^=http])").click(function(event) { if (event.metaKey || event.shiftKey || event.ctrlKey) { return;

    } event.preventDefault(); SimpleHistory.pushState(this.href); }); Friday, June 29, 2012
  3. SimpleHistory.start(function(url, state) { var parts = URL.parse(url); var path =

    parts.path; var index = path === "/"; $(document.body).toggleClass("indexActive", index); if (!index) { var photo = photos.lookup(path); $("#photo img").attr("src", photo.src); $("#photo p").text( photo.description ); } }); Friday, June 29, 2012
  4. twitter.com/bassistance vs twitter.com/#!/bassistance Never available on server Only as fallback

    Not necessary, as we’ll see soon What about hashchanges? Friday, June 29, 2012
  5. // double client/server export var photos; if (typeof exports !==

    'undefined') { photos = exports; } else { photos = {}; } photos.data = [{ src: "/alligators/DSC_1165.jpg", description: "Not a crocodile" }, ...]; photos.lookup = function(url) { return photos.data.filter(function(photo) { return photo.url == url; })[0]; }; Friday, June 29, 2012
  6. window.onerror = function(message, file, line) { window.onerror = function() {};

    logError("global", message, file + ":" + line); }; Friday, June 29, 2012
  7. Further reading: https://github.com/jzaefferer/pitfalls-examples Short link: http://git.io/Hirx3Q Looking for your feedback:

    http://www.surveymonkey.com/s/2F63MML Short link: http://svy.mk/xtVS2F @bassistance - [email protected] Friday, June 29, 2012