Slide 1

Slide 1 text

SINGLE PAGE APPLICATIONS The Good, the Bad and the Ugly Barnaby Cotter

Slide 2

Slide 2 text

ME Barnaby Cotter Developer at Parallax @brnctr

Slide 3

Slide 3 text

WHAT’S A SPA?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

NOPE, NOT THIS EITHER

Slide 6

Slide 6 text

SO WHAT ARE THEY? “Single Page” refers to a single browser refresh It does not mean that there is only one ‘page’. Because that wouldn’t make for a very good application.

Slide 7

Slide 7 text

SO WHY… ARE THEY? Imagine the year is 1999 - Javascript is a different beast. • Awesome cursor trailers • … • … • … not much else. But even then we pretty much had the XMLHTTPRequest But it didn’t get much use until…

Slide 8

Slide 8 text

GUESS WHO? •Pioneered a bunch of cool web tech •Now a megalomaniac company bent on world dominion •Set the bar for large scale web applications

Slide 9

Slide 9 text

THE BIRTH OF THE LIBRARY Prototype, Dojo, Mootools, ExtJS, jQuery

Slide 10

Slide 10 text

$.AJAX(“EVERYTHING”) My god… the power

Slide 11

Slide 11 text

Unwitting Developers “Cool Web Application” v9.31.15

Slide 12

Slide 12 text

WITH GREAT POWER… With big web applications becoming a thing, suddenly multiple developers need to work together.

Slide 13

Slide 13 text

MAIN.JS

Slide 14

Slide 14 text

TAKING A CUE FROM THE SERVER SIDE • A big tangled web of concerns. • Didn’t they invent that MVC thing in like, the 80s? • Can we apply those principles to the browser?

Slide 15

Slide 15 text

CONVENTION • Convention over configuration • Models live in /models, views live in /views • Controllers live in /views/models/docs/bin (not really)

Slide 16

Slide 16 text

THE BIRTH OF THE MV* FRAMEWORK Backbone, Angular, Ember… React?

Slide 17

Slide 17 text

BACKBONE • Released in 2010, maker of Coffeescript and underscore.js • lightweight - 6.3kb minified, 850 lines. • Vanilla JS • MV Framework • Flexible & Extensible - not just SPAs.

Slide 18

Slide 18 text

app.TodoView = Backbone.View.extend({ template: _.template($('#item-template').html()), events: { 'click .destroy': 'clear', }, initialize: function () { this.listenTo(this.model, 'destroy', this.remove); }, render: function () { this.$el.html(this.template(this.model.toJSON())); } clear: function() { //etc etc } });

Slide 19

Slide 19 text

USE CASE • New to SPAs? Usable for small projects - no crazy requirements • Experienced devs? More complex projects. Will go awry if you are undisciplined.

Slide 20

Slide 20 text

ANGULAR • Google - 2012 • ‘Monolithic’ framework • 2 way data binding • Declarative code for UI, Imperative code for Models

Slide 21

Slide 21 text

EXAMPLE http://jsfiddle.net/U3pVM/13770

Slide 22

Slide 22 text

USE CASE Rapid prototyping of a SPA Complex, multilayered UIs Large development teams Easy -> Confusing and Difficult -> Not Too Bad After All

Slide 23

Slide 23 text

EMBER IN BRIEF • In essence very similar to Angular • Strict adherence to web standards, future-proofed • Good routing • Automagically wires up everything • Use case similar to angular

Slide 24

Slide 24 text

REACT • 2014 Project from Facebook and Instagram • Described as just the V in MVC. • Quickly build UIs • Virtual DOM & server-side rendering • Elements written as .jsx files - inline JS and HTML. • Can be combined with Flux - FB’s architecture.

Slide 25

Slide 25 text

COMMON THEMES • Component based development. • Previous versions approximated web components • Self contained units of functionality - their own HTML, CSS, JS.

Slide 26

Slide 26 text

THE FUTURE • Moving towards component based architecture • e.g. Angular 2 removes controllers entirely • Modular frameworks • Pick and choose what you want

Slide 27

Slide 27 text

PICKING THE NEXT BIG JS FRAMEWORK

Slide 28

Slide 28 text

IT DOESN’T MATTER THEY’RE ALL GOOD Principles remain the same - they all help you build clean, convention based applications with reusable elements.

Slide 29

Slide 29 text

THANKS!