2013 10-02-backbone-robots-aarhus

44
ROBOTS HATE YOUR SINGLE-PAGE APP, LONG LIVE THE ROBOT Niklas Lindgren SC5 Online Ltd

description

SC5 and A-Lehdet just launched a responsive and adaptive website for Tuulilasi, the Finnish media authority for tech reviews of cars and other gadgets. This website relies heavily on search engine traffic, so we needed to support server side rendering. On the other hand we really wanted to use a single page app, but we didn't want to duplicate efforts. This talk shows why the ability to share code between the browser and the server is the best thing since sliced bread. We leveraged this possibility to develop a platform that allows us to run the same application in both environments, ultimately achieving a single page app that also caters to robots.

Transcript of 2013 10-02-backbone-robots-aarhus

Page 1: 2013 10-02-backbone-robots-aarhus

ROBOTS HATE YOUR SINGLE-PAGE APP, LONG LIVE THE ROBOT

Niklas LindgrenSC5 Online Ltd

Page 2: 2013 10-02-backbone-robots-aarhus

Hello World!

My name is Niklas, I’m on the internet:

http://nikc.org/+

http://nikc.org/@

(@nikcorg)

Page 3: 2013 10-02-backbone-robots-aarhus

A Single-Page App

<!doctype html>

<html>

<head>

<meta charset=”utf-8”>

<title>My Awesome Single-Page App</title>

<script src=”/js/app.js”></script>

</head>

<body/>

</html>

Page 4: 2013 10-02-backbone-robots-aarhus

Robots?

https://developers.google.com/webmasters/ajax-crawling/

Page 5: 2013 10-02-backbone-robots-aarhus

From Start to Finish

TodayThe beginning

Page 6: 2013 10-02-backbone-robots-aarhus

Today

Page 7: 2013 10-02-backbone-robots-aarhus

Rewind 9 Months

The beginning

Toying with the idea

Page 8: 2013 10-02-backbone-robots-aarhus

Sharing is Caring

Page 9: 2013 10-02-backbone-robots-aarhus

Choosing the Building Blocks

Page 10: 2013 10-02-backbone-robots-aarhus

Backbone&

Underscore

Page 11: 2013 10-02-backbone-robots-aarhus
Page 12: 2013 10-02-backbone-robots-aarhus

LayoutManager&

jQuery / Cheerio

http://layoutmanager.org/

Page 13: 2013 10-02-backbone-robots-aarhus

Q.js

https://github.com/kriskowal/q

Page 14: 2013 10-02-backbone-robots-aarhus

Handlebars

Page 15: 2013 10-02-backbone-robots-aarhus

A Quick Aside About Modules

Page 16: 2013 10-02-backbone-robots-aarhus

UMDhttps://github.com/umdjs/umd

Page 17: 2013 10-02-backbone-robots-aarhus

Cajonhttps://github.com/requirejs/cajon

Page 18: 2013 10-02-backbone-robots-aarhus

RequireJShttp://requirejs.org/

Page 19: 2013 10-02-backbone-robots-aarhus

Code Sharing Demohttps://github.com/nikcorg/commonjs-and-amd

Page 20: 2013 10-02-backbone-robots-aarhus

#Include Drupal

Page 21: 2013 10-02-backbone-robots-aarhus

Getting the Ball Rolling

Page 22: 2013 10-02-backbone-robots-aarhus

Talk HTTP to Me

Page 23: 2013 10-02-backbone-robots-aarhus

Wait...Wait...Wait...Wait...OK

Page 24: 2013 10-02-backbone-robots-aarhus

Finding Our Way to the Data

Page 25: 2013 10-02-backbone-robots-aarhus

This Might Actually Work

The beginning

Toying with the idea

First working prototype

Page 26: 2013 10-02-backbone-robots-aarhus

Dear Button,

Y U NO CLICK?

Page 27: 2013 10-02-backbone-robots-aarhus

Rebooting in the Browser

Page 28: 2013 10-02-backbone-robots-aarhus

Rebooting in the Browser

var FooView = module.exports = Backbone.Layout.extend({

});

Page 29: 2013 10-02-backbone-robots-aarhus

Rebooting in the Browser

var FooView = module.exports = Backbone.Layout.extend({

events: {

"change select": "onClick",

"submit": "onSubmit"

},

onClick: function (ev) {

// Magic

},

onSubmit: function (ev) {

// More magic

}

});

Page 30: 2013 10-02-backbone-robots-aarhus

Rebooting in the Browser

var FooView = module.exports = Backbone.Layout.extend({

attributes: {

"data-reboot-as": "views/foo"

}

});

Page 31: 2013 10-02-backbone-robots-aarhus

Rebooting in the Browser

var FooView = module.exports = Backbone.Layout.extend({

attributes: {

"data-reboot-as": "views/foo"

},

staticInit: function () {

// Hello World!

}

});

Page 32: 2013 10-02-backbone-robots-aarhus

Academia Is Perfect For Laboratory Conditions

Page 33: 2013 10-02-backbone-robots-aarhus

From Start to Finish

TodayThe beginning

Toying with the idea

First working prototype

Real work begins

Oh shit.

OH YEAH!

Oh shit.

OH YEAH!

Page 34: 2013 10-02-backbone-robots-aarhus

Working With A Less Than Ideal API

Drupal Client

Page 35: 2013 10-02-backbone-robots-aarhus

Working With A Less Than Ideal API

Drupal Client

Page 36: 2013 10-02-backbone-robots-aarhus

Node.js

#Include Drupal+Magic

Drupal Client

Page 37: 2013 10-02-backbone-robots-aarhus

The Joy of Existing in More Than One Environment

Page 38: 2013 10-02-backbone-robots-aarhus

Self-Contained Views

Page 39: 2013 10-02-backbone-robots-aarhus

No Hard Dependencies

Page 40: 2013 10-02-backbone-robots-aarhus

There’s Always an Exception

Page 41: 2013 10-02-backbone-robots-aarhus

Third Party Integrations

Page 42: 2013 10-02-backbone-robots-aarhus

What if I Don't Want a Single-Page App?

Page 43: 2013 10-02-backbone-robots-aarhus

What a Shiny Toy! Can I Play With It?

Page 44: 2013 10-02-backbone-robots-aarhus

Questions?

Twitter: @nikcorgGoogle+: http://nikc.org/+