Top Banner
The Dark Side of Single Page Applications Dor Kalev, CTO @ FTBpro
22

The Dark Side of Single Page Applications

Jan 15, 2015

Download

Technology

Dor Kalev

The story of all the pitfalls we had while transferring FTBpro.com from the good old web to a Backbone single page application... and all the great solutions we've came up with
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Dark Side of Single Page Applications

The Dark Side of Single Page Applications

Dor Kalev, CTO @ FTBpro

Page 2: The Dark Side of Single Page Applications

Dor Kalev

• Age 31

• Professional Body Builder

• Railer since 2005

• CTO @ FTBpro

Page 3: The Dark Side of Single Page Applications

FTBproLargest Fan-Generated Digital Media Platform in Football

Page 4: The Dark Side of Single Page Applications

FTBproAlso on mobile...

Page 5: The Dark Side of Single Page Applications

Web’s Evolution

• Web Applications are much more sophisticated

• JavaScript is much faster today

• AJAX & Sockets

• MV* Frameworks everywhere

Page 6: The Dark Side of Single Page Applications

What is a Single Page Application?

• Self contained webpage

• Complex but slick User Interaction

• Allows using 100% Client Side technology for the Client Side

• MVC 2.0 / MVP / MV*

• Right UX for the Mobile Web - Phone & Tablet

• www.slashdotslash.com

Page 7: The Dark Side of Single Page Applications

Why BackBone?

• Light weight

• Fits our heavy customization

• But why not? Ember, Angular are more robust

Page 8: The Dark Side of Single Page Applications

Using Presenters• Each Web Componenet / BackBone

Model is linked to a Presenter that supplies data in Json

• Fully tested - RSpec & Mocha

• Each Presenter manages its own Redis cache that is sweeped by the relevant Models on updates

• Thin Models, no Controllers

• Recommended regardless of SPA

Page 9: The Dark Side of Single Page Applications

What’s PIPE?

• In BackBone each Model AJAXes his data separately

• PIPE creates a single aggregated AJAX Request per page

• PIPE data queries are always based on the URL not cookies

• PIPE can be put on CDN

BackBone Model

BackBone Model

BackBone Model

BackBone Model

PIPE SERVER

Page 10: The Dark Side of Single Page Applications

Generators

• A generator for all MVP files + Tests

• Faster development process

• Sets a standard

• Read more:http://tech.ftbpro.com/post/62148484009/speed-up-your-development-process-with-yeoman

Page 11: The Dark Side of Single Page Applications

ENTER THE DARK SIDE

Page 12: The Dark Side of Single Page Applications

Caveats

• How will Google read the page’s content?

• First page takes time to load, using Ajax loader on first load is ugly

• How to use CDN?

• Lousy Mobile performance

Page 13: The Dark Side of Single Page Applications

SOLUTION

RENDER ON THE SERVER

Page 14: The Dark Side of Single Page Applications

Render on the Server

• Use escaped Fragment + Phantom.js

• Just Jader everything

• Phantom.js + Rndr.me as a middle ware

• Phantom.js + Rndr.me as a supervised middle ware

Page 15: The Dark Side of Single Page Applications

JADERhttps://github.com/zohararad/jader

• Using Serverside JavaScript render jade templates on the server

• UPS:

• Stay in Rails context without Phantom.js

• Share JavaScript templates between client & server

• DOWNS:

• Slow rendering

• Duplicate server logic

Page 16: The Dark Side of Single Page Applications

Classic Phantom.js

NGINX + MEMCACHED

CLIENT

PHANTOM.JS

RAILS

RESQUE

or usehttp://www.brombone.com/

Page 17: The Dark Side of Single Page Applications

Phantom.js as Middleware

• Use Phantom.js directly with the client

• Phantom.js calls should be cached because it can’t stand the load

• Use Phantom Manager to manage multiple Phantom.js instances https://github.com/FTBpro/phantom-manager

PHANTOM.JS + CACHE

CLIENT

RAILS

Page 18: The Dark Side of Single Page Applications

Supervised Phantom.js

• If we have to live with it, let’s control it

• Serve Phantom.js when possible, fall back to standard SPA when Phantom.js times out

• Use Phantom Manager

• STABLE AT LAST!

RAILS + CACHE

CLIENT

PHANTOM

RAILS

Page 19: The Dark Side of Single Page Applications

Caching Solutions

• Localstorage

• CDN

• Full page caching

• PIPE

• Memcached for Phantom.js render output

• REDIS for Presenters

• BONUS: ElasticSearch & NEO4J for Data

Page 20: The Dark Side of Single Page Applications

Everything is Amazing

• Fast UX

• Web servers rest

• Database rests

• Faster development

• Full control of caching tiers

• Rule client-side with client-side technology

• Unify mobile web with desktop web (m.ftbpro.com = ftbpro.com)

Page 21: The Dark Side of Single Page Applications

Thank you! Questions?

Page 22: The Dark Side of Single Page Applications

Visittech.ftbpro.com

for more...