I started wondering why
all software,
without exception,
isn’t written this way.
Slide 41
Slide 41 text
three rules
crash-only
loose coupling
remove decoration
Slide 42
Slide 42 text
three principles
web
native
hybrid
Slide 43
Slide 43 text
three principles
death is certain
you’re not alone
stop doing so much
Slide 44
Slide 44 text
WARNING
pseudocode
ahead
Slide 45
Slide 45 text
death is certain
Slide 46
Slide 46 text
nasty, brutish and short
‣ killed by the OS (or the browser)
‣ interrupted
‣ network dropped
Slide 47
Slide 47 text
$.on(‘deviceready’, function () {
// BAD
lotsOfExpensiveOperations()
// GOOD
minimalStartup()
})
start up quickly
Slide 48
Slide 48 text
$.on(‘resume’, function () {
resumeAppState()
})
listen for lifecycle events
$.on(‘pause’, function () {
saveAppState()
})
Slide 49
Slide 49 text
$.on(‘offline’, function () {
app.hasNetwork = false
})
listen to the network
$.on(‘online’, function () {
app.hasNetwork = true
})
Slide 50
Slide 50 text
$.on(‘anythingImportant’, function () {
saveDataLocally()
replicateWithServer()
})
always save state!
always!
Slide 51
Slide 51 text
you’re not alone
Slide 52
Slide 52 text
your (okay) app
lists + buttons
data
Slide 53
Slide 53 text
your (super) app
lists + buttons
data
the world
Slide 54
Slide 54 text
‣ Web: hyperlinks!
‣ Android: intents
‣ iOS: custom URL scheme
‣ future: web intents
communication
Slide 55
Slide 55 text
function share(thing, where) {
if (where == ‘facebook’) {
fbShare(thing)
} else if (where == ‘twitter’) {
twitterShare(thing)
} else {
alert(“don’t use “ + where)
}
})
roll your own
Slide 56
Slide 56 text
function share(thing, where) {
if (where == ‘facebook’) {
open(“fb://” + thing)
} else if (where == ‘twitter’) {
open(“twitter://” + thing)
} else {
alert(“don’t use “ + where)
}
})
URL schemes
Slide 57
Slide 57 text
Register Service
see webintents.org
Slide 58
Slide 58 text
var intent = new Intent("http://
webintents.org/share",
"text/uri-list",
"http://news.bbc.co.uk");
window.navigator.startActivity(int
ent);
Invoke Action
see webintents.org
Slide 59
Slide 59 text
stop doing so much
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
http://bit.ly/pg-native
Slide 62
Slide 62 text
And then... *pow*...
performance issues that
weren't related to anything
that I could find: it seemed
some combination of CSS/
HTML/JavaScript was getting
in the way.
Slide 63
Slide 63 text
I've finally pared it down to
nothing but Zepto
unless I really really need
something else. Even just
getting away from
core JQuery makes a big
difference.
Slide 64
Slide 64 text
do you need
a scrolling library
a UI library
an MVC library
boilerplate
Slide 65
Slide 65 text
var $ =
document.querySelectorAll.bind(document)
// and something like
Element.prototype.on =
Element.prototype.addEventListener
$(‘#mylink’)[0].on(‘touchstart’,
handleTouch, false)
Use what’s there
Slide 66
Slide 66 text
avoid decoration
Slide 67
Slide 67 text
build lots of
small apps
Slide 68
Slide 68 text
you can always
have less code
Slide 69
Slide 69 text
death is certain
you’re not alone
stop doing so much
Slide 70
Slide 70 text
Thank You
@alunny
build.phonegap.com
links: http://bit.ly/devcon-links