Structuring web applications with Backbone.js

Diego Cardozo
Diego CardozoPrincipal Performance Engineer at Oracle
Structuring	web	applications
with	Backbone.js
		
Diego	Cardozo
github.com/diegocard/backbone-presentation
Goals
This	presentation	isn't	only	a	Backbone	tutorial
We'll	focus	on	complex	client	design
Using	Backbone	as	the	main	tool
Most	concepts	won't	be	tool-specific
Can	be	applied	to	other	tools	like	Angular	or	Knockout
We'll	learn	Backbone	through	examples
What	do	I	want	you	to	learn?
Useful	concepts	for	complex	web	client	design
Basic	Backbone	knowledge
Motivation	to	keep	learning
For	those	who	already	know	Backbone
Good	practices
Combination	with	other	tools
Agenda
1.	 Introduction
2.	 Architecture
3.	 Example
4.	 Backbone	components
5.	 Structuring	a	web	application
Introduction	(1)
Web	clients	have	better	resources	every	day
We	can	now	build	smart	clients
But	complex	applications	with	jQuery...	
Are	hard	to	build
Lack	structure
Do	not	favor	reutilization
Creating	your	own	structure	is	reinventing	the	wheel
Introduction	(2)
Introduction	(3)
Backbone	gives	us	
Structure	for	our	client-side	JavaScript	code
Several	utilities
Basically,	it	is	a	MV*	framework
We	organize	code	in	different	components
Models
Collections
Views
Templates
Routers
Architecture	(1)
Architecture	(2)
Advantages
Maintainability
Load	distribution	
Quicker	start	to	the	development	process
UI	is	only	another	client
Great	for	testing
Perfect	for	combining	with	mobile	apps
Examplegithub.com/diegocard/backbone-presentation/demo
Components	(1)
Model
var	User	=	Backbone.Model.extend({
						urlRoot:	'/users'
});
Components	(2)
Collection
var	Users	=	Backbone.Collection.extend({
								url:	'/users'
});
Components	(3)
View
var	UserListView	=	Backbone.View.extend({
				el:	'.page',
				render:	function	()	{
								var	that	=	this;
								var	users	=	new	Users();
								users.fetch({
												success:	function	(users)	{
																var	template	=	_.template(
																				$('#user-list-template').html(),
																				{users:	users.models}
																);
																that.$el.html(template);
												}
								})
				}
});
Components	(4)
Event	handling
var	UserEditView	=	Backbone.View.extend({
				el:	'.page',
				events:	{
								'submit	.edit-user-form':	'saveUser',
								'click	.delete':	'deleteUser'
				},
				saveUser:	function	(ev)	{
								var	userDetails	=	$(ev.currentTarget).serializeObject();
								var	user	=	new	User();
								user.save(userDetails,	{
												success:	function	(user)	{
																router.navigate('',	{trigger:true});
												}
								});
				}
});
Components	(5)
Template
<script	type="text/template"	id="user-list-template">
		<a	href="#/new"	class="btn	btn-primary">New</a>
		<hr	/>
		<table	class="table	striped">
				<thead>
						<tr>
								<th>First	Name</th><th>Last	Name</th><th>Age</th><th></th>
						</tr>
				</thead>
				<tbody>
						<%	_.each(users,	function(user)	{	%>
								<tr>
										<td><%=	htmlEncode(user.get('firstname'))	%></td>
										<td><%=	htmlEncode(user.get('lastname'))	%></td>
										<td><%=	htmlEncode(user.get('age'))	%></td>
										<td><a	class="btn"	href="#/edit/<%=	user.id	%>">Edit</a></td>
								</tr>
						<%	});	%>
				</tbody>
		</table>
</script>
Components	(6)
Router
	var	Router	=	Backbone.Router.extend({
					routes:	{
									"":	"home",	
									"edit/:id":	"edit",
									"new":	"edit",
					}
	});
Structure	(1)
Using	backbone	doesn't	guarantee	good	practices
We	need	to	organize	and	modularize	our	application
We	can	use	Require.js	to	achieve	this
I	found	a	great	example	at:
backbonetutorials.com/organizing-backbone-using-modules
Structure	(2)
Suggested	structure
Root
├──	imgs
├──	css
│			└──	style.css
├──	templates
│			├──	projects
│			│			├──	list.html
│			│			└──	edit.html
│			└──	users
│							├──	list.html
│							└──	edit.html
├──	js
│			├──	libs
│			│			├──	jquery
│			│			│			├──	jquery.min.js
│			│			├──	backbone
│			│			│			├──	backbone.min.js
│			│			└──	underscore
│			│			│			├──	underscore.min.js
│			├──	models
│			│			├──	users.js
Structure	(3)
Example:	Proyect	list	
define([
		'jquery',
		'underscore',
		'backbone',
		//	Using	the	text!	plugin	for	Require.js,	
		//	we	can	load	templates	as	plain	text
		'text!templates/project/list.html'
],	function($,	_,	Backbone,	projectListTemplate){
		var	ProjectListView	=	Backbone.View.extend({
				el:	$('#container'),
				render:	function(){
						//	Compile	the	template	with	underscore
						//	and	add	the	template	to	the	view	element
						var	data	=	{};
						var	compiledTemplate	=	_.template(projectListTemplate,	data);
						this.$el.append(compiledTemplate);
				}
		});
		return	ProjectListView;	//	Return	the	view
});
Resources
	
	
	
backbonejs.org
backbonetutorials.com
addyosmani.github.io/backbone-fundamentals
github.com/diegocard/backbone-presentation
¿Questions?
1 of 21

Recommended

Writing HTML5 Web Apps using Backbone.js and GAE by
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
12.2K views32 slides
Introduction to Backbone.js by
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.jsPragnesh Vaghela
5.2K views14 slides
Introduction to backbone js by
Introduction to backbone jsIntroduction to backbone js
Introduction to backbone jsMindfire Solutions
1.1K views18 slides
Introduction to backbone_js by
Introduction to backbone_jsIntroduction to backbone_js
Introduction to backbone_jsMohammed Saqib
870 views24 slides
Creating MVC Application with backbone js by
Creating MVC Application with backbone jsCreating MVC Application with backbone js
Creating MVC Application with backbone jsMindfire Solutions
1.6K views17 slides
Александр Белецкий "Архитектура Javascript приложений" by
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"Agile Base Camp
2K views44 slides

More Related Content

What's hot

Beginning In J2EE by
Beginning In J2EEBeginning In J2EE
Beginning In J2EESuthat Rongraung
493 views14 slides
Give your web apps some backbone by
Give your web apps some backboneGive your web apps some backbone
Give your web apps some backboneRTigger
760 views11 slides
iOS Architectures by
iOS ArchitecturesiOS Architectures
iOS ArchitecturesHung Hoang
1.1K views27 slides
Introduction to react js and reasons to go with react js in 2020 by
Introduction to react js and reasons to go with react js in 2020Introduction to react js and reasons to go with react js in 2020
Introduction to react js and reasons to go with react js in 2020Concetto Labs
106 views15 slides
Lesson 09 by
Lesson 09Lesson 09
Lesson 09Gene Babon
492 views12 slides
Dog food conference creating modular webparts with require js in sharepoint by
Dog food conference   creating modular webparts with require js in sharepointDog food conference   creating modular webparts with require js in sharepoint
Dog food conference creating modular webparts with require js in sharepointfahey252
564 views31 slides

What's hot(20)

Give your web apps some backbone by RTigger
Give your web apps some backboneGive your web apps some backbone
Give your web apps some backbone
RTigger760 views
iOS Architectures by Hung Hoang
iOS ArchitecturesiOS Architectures
iOS Architectures
Hung Hoang1.1K views
Introduction to react js and reasons to go with react js in 2020 by Concetto Labs
Introduction to react js and reasons to go with react js in 2020Introduction to react js and reasons to go with react js in 2020
Introduction to react js and reasons to go with react js in 2020
Concetto Labs106 views
Dog food conference creating modular webparts with require js in sharepoint by fahey252
Dog food conference   creating modular webparts with require js in sharepointDog food conference   creating modular webparts with require js in sharepoint
Dog food conference creating modular webparts with require js in sharepoint
fahey252564 views
Dicoding Developer Coaching #34: Android | Modular Android App dengan Dynamic... by DicodingEvent
Dicoding Developer Coaching #34: Android | Modular Android App dengan Dynamic...Dicoding Developer Coaching #34: Android | Modular Android App dengan Dynamic...
Dicoding Developer Coaching #34: Android | Modular Android App dengan Dynamic...
DicodingEvent183 views
Google Developer Group(GDG) DevFest Event 2012 Android talk by Imam Raza
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
Imam Raza1.4K views
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece by Dan Gribbin
Transforming Front-End Disaster Code™ Into A Maintainable MasterpieceTransforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Dan Gribbin11K views
React js, node js &amp; angular js which one is the best for web development by Concetto Labs
React js, node js &amp; angular js  which one is the best for web development React js, node js &amp; angular js  which one is the best for web development
React js, node js &amp; angular js which one is the best for web development
Concetto Labs46 views
AngularJS : Superheroic JavaScript MVW Framework by Edureka!
AngularJS : Superheroic JavaScript MVW FrameworkAngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW Framework
Edureka!3.6K views

Viewers also liked

Introduction To Backbone JS by
Introduction To Backbone JSIntroduction To Backbone JS
Introduction To Backbone JSparamisoft
955 views18 slides
Introduction to Backbone - Workshop by
Introduction to Backbone - WorkshopIntroduction to Backbone - Workshop
Introduction to Backbone - WorkshopOren Farhi
1.3K views26 slides
Backbone.js by
Backbone.jsBackbone.js
Backbone.jstonyskn
3.6K views6 slides
Backbone.js by
Backbone.jsBackbone.js
Backbone.jsChris Neale
2.7K views32 slides
Backbone Basics with Examples by
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with ExamplesSergey Bolshchikov
4.3K views27 slides
Sockets and rails by
Sockets and railsSockets and rails
Sockets and railsShrikanth Rajarajan
2.3K views28 slides

Viewers also liked(20)

Introduction To Backbone JS by paramisoft
Introduction To Backbone JSIntroduction To Backbone JS
Introduction To Backbone JS
paramisoft955 views
Introduction to Backbone - Workshop by Oren Farhi
Introduction to Backbone - WorkshopIntroduction to Backbone - Workshop
Introduction to Backbone - Workshop
Oren Farhi1.3K views
Backbone.js by tonyskn
Backbone.jsBackbone.js
Backbone.js
tonyskn3.6K views
Delivering HTML5 and Modern Apps by Joshua Drew
Delivering HTML5 and Modern AppsDelivering HTML5 and Modern Apps
Delivering HTML5 and Modern Apps
Joshua Drew850 views
Building modern web apps with html5, javascript, and java by Alexander Gyoshev
Building modern web apps with html5, javascript, and javaBuilding modern web apps with html5, javascript, and java
Building modern web apps with html5, javascript, and java
Alexander Gyoshev10.3K views
Modern Web App Architectures by Raphael Stary
Modern Web App ArchitecturesModern Web App Architectures
Modern Web App Architectures
Raphael Stary1.8K views
How to-choose-the-right-technology-architecture-for-your-mobile-application by lverb
How to-choose-the-right-technology-architecture-for-your-mobile-applicationHow to-choose-the-right-technology-architecture-for-your-mobile-application
How to-choose-the-right-technology-architecture-for-your-mobile-application
lverb839 views
Introduction To Building Enterprise Web Application With Spring Mvc by Abdelmonaim Remani
Introduction To Building Enterprise Web Application With Spring MvcIntroduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring Mvc
Abdelmonaim Remani4.5K views
Web Application Frameworks - Web Technologies (1019888BNR) by Beat Signer
Web Application Frameworks - Web Technologies (1019888BNR)Web Application Frameworks - Web Technologies (1019888BNR)
Web Application Frameworks - Web Technologies (1019888BNR)
Beat Signer2.4K views
Building a Single-Page App: Backbone, Node.js, and Beyond by Spike Brehm
Building a Single-Page App: Backbone, Node.js, and BeyondBuilding a Single-Page App: Backbone, Node.js, and Beyond
Building a Single-Page App: Backbone, Node.js, and Beyond
Spike Brehm29.5K views

Similar to Structuring web applications with Backbone.js

Introduction to MVC Web Framework with CodeIgniter by
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterPongsakorn U-chupala
8.8K views27 slides
Lotus Framework by
Lotus FrameworkLotus Framework
Lotus FrameworkTodi Adiyatmo
1.4K views30 slides
Single page applications by
Single page applicationsSingle page applications
Single page applicationsDiego Cardozo
2.4K views21 slides
JavaScript - Kristiansand PHP by
JavaScript - Kristiansand PHPJavaScript - Kristiansand PHP
JavaScript - Kristiansand PHPholeedave
325 views18 slides
AngularJS - A Powerful Framework For Web Applications by
AngularJS - A Powerful Framework For Web ApplicationsAngularJS - A Powerful Framework For Web Applications
AngularJS - A Powerful Framework For Web ApplicationsIdexcel Technologies
1.4K views12 slides
Noman Khan Internship Report 2.pptx by
Noman Khan Internship Report 2.pptxNoman Khan Internship Report 2.pptx
Noman Khan Internship Report 2.pptxNomanKhan869872
6 views43 slides

Similar to Structuring web applications with Backbone.js(20)

Introduction to MVC Web Framework with CodeIgniter by Pongsakorn U-chupala
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
Single page applications by Diego Cardozo
Single page applicationsSingle page applications
Single page applications
Diego Cardozo2.4K views
JavaScript - Kristiansand PHP by holeedave
JavaScript - Kristiansand PHPJavaScript - Kristiansand PHP
JavaScript - Kristiansand PHP
holeedave325 views
AngularJS - A Powerful Framework For Web Applications by Idexcel Technologies
AngularJS - A Powerful Framework For Web ApplicationsAngularJS - A Powerful Framework For Web Applications
AngularJS - A Powerful Framework For Web Applications
Why do JavaScript enthusiast think of Vue.js for building real-time web appli... by Katy Slemon
Why do JavaScript enthusiast think of Vue.js for building real-time web appli...Why do JavaScript enthusiast think of Vue.js for building real-time web appli...
Why do JavaScript enthusiast think of Vue.js for building real-time web appli...
Katy Slemon43 views
Internship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdf by VitulChauhan
Internship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdfInternship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdf
Internship-Report-VitulChauhan-18132023-IT_CRUD-OPERATION.pdf
VitulChauhan53 views
AngularJS in Production (CTO Forum) by Alex Ross
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)
Alex Ross849 views
Vuejs and Web components - current state by Mikhail Kuznetcov
Vuejs and Web components - current stateVuejs and Web components - current state
Vuejs and Web components - current state
Mikhail Kuznetcov667 views
Building reusable components as micro frontends with glimmer js and webcompo... by Andrei Sebastian Cîmpean
Building reusable components as micro frontends  with glimmer js and webcompo...Building reusable components as micro frontends  with glimmer js and webcompo...
Building reusable components as micro frontends with glimmer js and webcompo...
Selecting the Best Javascript Web Framework by Rajitha Pathiraja
Selecting the Best Javascript Web FrameworkSelecting the Best Javascript Web Framework
Selecting the Best Javascript Web Framework
Rajitha Pathiraja168 views

More from Diego Cardozo

El proximo billon de usuarios by
El proximo billon de usuariosEl proximo billon de usuarios
El proximo billon de usuariosDiego Cardozo
143 views19 slides
The next billion users by
The next billion usersThe next billion users
The next billion usersDiego Cardozo
237 views19 slides
Troubleshooting Ecommerce Performance by
 Troubleshooting Ecommerce Performance Troubleshooting Ecommerce Performance
Troubleshooting Ecommerce PerformanceDiego Cardozo
174 views72 slides
Cranking It Up - SuiteWorld 2017 by
Cranking It Up  - SuiteWorld 2017Cranking It Up  - SuiteWorld 2017
Cranking It Up - SuiteWorld 2017Diego Cardozo
149 views72 slides
Speed Thrills - Suiteworld 2016 by
Speed Thrills - Suiteworld 2016Speed Thrills - Suiteworld 2016
Speed Thrills - Suiteworld 2016Diego Cardozo
117 views43 slides
Performance in the cloud by
Performance in the cloudPerformance in the cloud
Performance in the cloudDiego Cardozo
302 views12 slides

More from Diego Cardozo(15)

El proximo billon de usuarios by Diego Cardozo
El proximo billon de usuariosEl proximo billon de usuarios
El proximo billon de usuarios
Diego Cardozo143 views
Troubleshooting Ecommerce Performance by Diego Cardozo
 Troubleshooting Ecommerce Performance Troubleshooting Ecommerce Performance
Troubleshooting Ecommerce Performance
Diego Cardozo174 views
Cranking It Up - SuiteWorld 2017 by Diego Cardozo
Cranking It Up  - SuiteWorld 2017Cranking It Up  - SuiteWorld 2017
Cranking It Up - SuiteWorld 2017
Diego Cardozo149 views
Speed Thrills - Suiteworld 2016 by Diego Cardozo
Speed Thrills - Suiteworld 2016Speed Thrills - Suiteworld 2016
Speed Thrills - Suiteworld 2016
Diego Cardozo117 views
Performance in the cloud by Diego Cardozo
Performance in the cloudPerformance in the cloud
Performance in the cloud
Diego Cardozo302 views
Cómo testear performance sin morir en el intento by Diego Cardozo
Cómo testear performance sin morir en el intentoCómo testear performance sin morir en el intento
Cómo testear performance sin morir en el intento
Diego Cardozo409 views
Optimize performance and not die trying by Diego Cardozo
Optimize performance and not die tryingOptimize performance and not die trying
Optimize performance and not die trying
Diego Cardozo1.2K views
Optimizar performance sin morir en el intento by Diego Cardozo
Optimizar performance sin morir en el intentoOptimizar performance sin morir en el intento
Optimizar performance sin morir en el intento
Diego Cardozo386 views
How to test performance and not die trying by Diego Cardozo
How to test performance and not die tryingHow to test performance and not die trying
How to test performance and not die trying
Diego Cardozo721 views
Testeando performance sin morir en el intento by Diego Cardozo
Testeando performance sin morir en el intentoTesteando performance sin morir en el intento
Testeando performance sin morir en el intento
Diego Cardozo458 views
Organización de aplicaciones web con Backbone.js by Diego Cardozo
Organización de aplicaciones web con Backbone.jsOrganización de aplicaciones web con Backbone.js
Organización de aplicaciones web con Backbone.js
Diego Cardozo1.5K views
Component Based Software Development by Diego Cardozo
Component Based Software DevelopmentComponent Based Software Development
Component Based Software Development
Diego Cardozo2.9K views
Desarrollo de Software Basado en Componentes by Diego Cardozo
Desarrollo de Software Basado en ComponentesDesarrollo de Software Basado en Componentes
Desarrollo de Software Basado en Componentes
Diego Cardozo1.9K views
Single Page Applications by Diego Cardozo
Single Page ApplicationsSingle Page Applications
Single Page Applications
Diego Cardozo2.4K views

Recently uploaded

Mobile App Development Company by
Mobile App Development CompanyMobile App Development Company
Mobile App Development CompanyRichestsoft
5 views6 slides
Supercharging your Python Development Environment with VS Code and Dev Contai... by
Supercharging your Python Development Environment with VS Code and Dev Contai...Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...Dawn Wages
5 views51 slides
Ports-and-Adapters Architecture for Embedded HMI by
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMIBurkhard Stubert
35 views19 slides
Using Qt under LGPL-3.0 by
Using Qt under LGPL-3.0Using Qt under LGPL-3.0
Using Qt under LGPL-3.0Burkhard Stubert
14 views11 slides
Advanced API Mocking Techniques Using Wiremock by
Advanced API Mocking Techniques Using WiremockAdvanced API Mocking Techniques Using Wiremock
Advanced API Mocking Techniques Using WiremockDimpy Adhikary
5 views11 slides
Flask-Python by
Flask-PythonFlask-Python
Flask-PythonTriloki Gupta
10 views12 slides

Recently uploaded(20)

Mobile App Development Company by Richestsoft
Mobile App Development CompanyMobile App Development Company
Mobile App Development Company
Richestsoft 5 views
Supercharging your Python Development Environment with VS Code and Dev Contai... by Dawn Wages
Supercharging your Python Development Environment with VS Code and Dev Contai...Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...
Dawn Wages5 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert35 views
Advanced API Mocking Techniques Using Wiremock by Dimpy Adhikary
Advanced API Mocking Techniques Using WiremockAdvanced API Mocking Techniques Using Wiremock
Advanced API Mocking Techniques Using Wiremock
Dimpy Adhikary5 views
FOSSLight Community Day 2023-11-30 by Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan8 views
Transport Management System - Shipment & Container Tracking by Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views
predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app10 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite7 views
Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic16 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67026 views

Structuring web applications with Backbone.js