SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
An overview of
Scalable Web Application Front-end
Saeid Zebardast
http://zebardast.com
@saeidzeb
1
An overview of Scalable Web Application Front-end
Problem Definition
Building large web applications with dozens of developers is a difficult task. Organizing the engineers
around a common goal is one thing, but organizing your code so that people can work efficiently is
another. Many large applications suffer from growing pains after just a few months in production due to
poorly designed JavaScript with unclear upgrade and extension paths.
Scalable JavaScript Application Framework
Yahoo! home page engineer Nicholas Zakas1
, author of Professional JavaScript for Web Developers,
introduced front-end architecture for complex, modular web applications with significant JavaScript
elements.
1 nczonline.net
2
Figure 1: Scalable JavaScript Application Architecture by N. Zakas
Module
An independent unit of functionality that is part of the total structure of a web application. Web
application modules consist of HTML, CSS and JavaScript.
Module rules
• Any single module should be able to live on its own
• Loose coupling allows you to make changes to one module without affecting the others
• Each module has its own sandbox
◦ An interface with which the module can interact to ensure loose coupling
• Modules have limited knowledge and only know the sandbox
◦ Each module knows about their sandbox and that's it The rest of the architecture doesn't
exist to them.
• Only call your own methods or those on the sandbox
• Don't access DOM elements outside of your box
• Don't access non-native global objects
• Anything else you need, ask the sandbox
• Don't create global objects
• Don't directly reference other modules
• Modules must stay within their own sandboxes
◦ No matter how restrictive or uncomfortable it may seem
Sandbox
The sandbox ensures a consistent interface. Modules can rely on the methods to always be there. The
sandbox also acts like a security guard. It knows what the modules are allowed to access and do on the
framework.
Sandbox jobs
• Consistency
• Security
• Communication
3
Application Core
The application core manages modules. The application core tells a module when it should initialize
and when it should shutdown. Also, it manages communication between modules.
The application core handles errors. It uses available information to determine best course of action.
Application core jobs
• Manage module lifecycle
• Enable inter-module communication
• General error handling
• Be extensible by plugins
Mediator
The application core handles the messages by using Mediator class.
Plugins
Plugins augment the capabilities of the core to keep it relevant and useful. Anything built for extension
can never be obsolete.
What plugins can be created
• Error handling
• Ajax communication
• New module capabilities
• General utilities
• Anything!
Base Library
The base library provides basic functionality. Most applications are too tightly coupled to the base
library. Developers get upset when they can't touch the base library. Ideally, only the application core
has any idea what base library is being used.
4
Base library jobs
• Browser normalization
• General purpose utilities
◦ Parsers/Serializers for XML, JSON, etc.
◦ Object manipulation
◦ DOM manipulation
◦ Ajax communication
• Provide low-level extensibility
Advantages
• Multiple different applications can be created with the same framework.
• Each part can be tested separately
5
What's “scaleApp”?
scaleApp2
is a tiny JavaScript framework for scalable JavaScript Applications. The framework allows
you to easily create complex web applications. scaleApp is based on a decoupled, event-driven
architecture that is inspired by the talk of Nicholas C. Zakas - "Scalable JavaScript Application
Architecture".
Quick start using “scaleApp”?
Link scaleApp.min.js in your HTML file:
<script src="scaleApp.min.js"></script>
Create a core
First of all create a new core instance:
var core = new scaleApp.Core();
Register modules
core.register( "myModuleId", function( sandbox ){
return {
init: function(){ /*...*/ },
destroy: function(){ /*...*/ }
};
});
As you can see the module is a function that takes the sandbox as a parameter and returns an object that
has two functions init and destroy (the latter is optional). Of course your module can be any usual class
with those two functions.
var MyGreatModule = function(sandbox){
return {
2 http://scaleapp.org
6
init: function(){ alert("Hello world!"); }
destroy: function(){ alert("Bye bye!"); }
};
};
core.register("myGreatModule", MyGreatModule);
The init function is called by the framework when the module is supposed to start. The destroy function
is called when the module has to shut down.
Start modules
After your modules are registered, start your modules:
core
.start( "myModuleId" )
.start( "anOtherModule", function(err){
// 'anOtherModule' is running now
});
Stopping
It's obvious:
core.stop("moduleB");
core.stop(); // stops all running instances
Publish/Subscribe
If the module needs to communicate with others, you can use the emit and on methods.
7
Emit
The emit function takes three parameters whereas the last one is optional:
• topic: the channel name you want to emit to
• data: the data itself
• cb: callback method
The emit function is accessible through the sandbox:
sandbox.emit( "myEventTopic", myData );
On
A message handler could look like this:
var messageHandler = function( data, topic ){
switch( topic ){
case "somethingHappend":
sandbox.emit( "myEventTopic", processData(data) );
break;
case "aNiceTopic":
justProcess( data );
break;
}
};
… and it can listen to one or more channels:
sub1 = sandbox.on( "somethingHappend", messageHandler );
sub2 = sandbox.on( "aNiceTopic", messageHandler );
8
Attach and Detach
A subscription can be detached and attached again:
sub.detach(); // don't listen any more
sub.attach(); // receive upcoming messages
Unsubscribe
You can unsubscribe a function from channel:
sandbox.off("a-channel", callback);
And you can remove a callback function from all channels:
sandbox.off(callback);
Or remove all subscriptions from a channel:
sandbox.off("channelName");
9

Más contenido relacionado

La actualidad más candente

Javascript Frameworks
Javascript FrameworksJavascript Frameworks
Javascript Frameworks
Mitesh Gandhi
 
Choosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkitChoosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkit
Hristo Chakarov
 

La actualidad más candente (15)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
Javascript Frameworks
Javascript FrameworksJavascript Frameworks
Javascript Frameworks
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
Choosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkitChoosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkit
 
Introduction to React and Flux (CodeLabs)
Introduction to React and Flux (CodeLabs)Introduction to React and Flux (CodeLabs)
Introduction to React and Flux (CodeLabs)
 
Struts course material
Struts course materialStruts course material
Struts course material
 
CRUD with Polymer 2.0
CRUD with Polymer 2.0CRUD with Polymer 2.0
CRUD with Polymer 2.0
 
Selenium Online Training
Selenium  Online TrainingSelenium  Online Training
Selenium Online Training
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
 
Dicoding Developer Coaching #37: Android | Kesalahan yang Sering Terjadi pada...
Dicoding Developer Coaching #37: Android | Kesalahan yang Sering Terjadi pada...Dicoding Developer Coaching #37: Android | Kesalahan yang Sering Terjadi pada...
Dicoding Developer Coaching #37: Android | Kesalahan yang Sering Terjadi pada...
 
Backbone And Marionette : Take Over The World
Backbone And Marionette : Take Over The WorldBackbone And Marionette : Take Over The World
Backbone And Marionette : Take Over The World
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture components
 
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
 

Destacado

Destacado (7)

What is good design?
What is good design?What is good design?
What is good design?
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Web Components Revolution
Web Components RevolutionWeb Components Revolution
Web Components Revolution
 
MySQL Cheat Sheet
MySQL Cheat SheetMySQL Cheat Sheet
MySQL Cheat Sheet
 
An Introduction to Apache Cassandra
An Introduction to Apache CassandraAn Introduction to Apache Cassandra
An Introduction to Apache Cassandra
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Less, But Better - Dieter Rams' Principles of Good Design
Less, But Better - Dieter Rams' Principles of Good DesignLess, But Better - Dieter Rams' Principles of Good Design
Less, But Better - Dieter Rams' Principles of Good Design
 

Similar a An overview of Scalable Web Application Front-end

Drupal module development
Drupal module developmentDrupal module development
Drupal module development
Rachit Gupta
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
Pragnesh Vaghela
 
Александр Белецкий "Архитектура Javascript приложений"
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"
Agile Base Camp
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
WO Community
 

Similar a An overview of Scalable Web Application Front-end (20)

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript Apps
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript Development
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
Plone FSR
Plone FSRPlone FSR
Plone FSR
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
Fundamentals of JAVA
Fundamentals of JAVAFundamentals of JAVA
Fundamentals of JAVA
 
Александр Белецкий "Архитектура Javascript приложений"
 Александр Белецкий "Архитектура Javascript приложений" Александр Белецкий "Архитектура Javascript приложений"
Александр Белецкий "Архитектура Javascript приложений"
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Building Reactive webapp with React/Flux
Building Reactive webapp with React/FluxBuilding Reactive webapp with React/Flux
Building Reactive webapp with React/Flux
 
Library Managemnet System
Library Managemnet SystemLibrary Managemnet System
Library Managemnet System
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
 
Building Top-Notch Androids SDKs
Building Top-Notch Androids SDKsBuilding Top-Notch Androids SDKs
Building Top-Notch Androids SDKs
 
Top java script frameworks ppt
Top java script frameworks pptTop java script frameworks ppt
Top java script frameworks ppt
 
Java 9 modularity+
Java 9 modularity+Java 9 modularity+
Java 9 modularity+
 

Más de Saeid Zebardast

Más de Saeid Zebardast (7)

Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
هفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیمهفده اصل افراد موثر در تیم
هفده اصل افراد موثر در تیم
 
How to be different?
How to be different?How to be different?
How to be different?
 
What is REST?
What is REST?What is REST?
What is REST?
 
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزادمعرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
معرفی گنو/لینوکس و سیستم عامل های متن باز و آزاد
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

An overview of Scalable Web Application Front-end

  • 1. An overview of Scalable Web Application Front-end Saeid Zebardast http://zebardast.com @saeidzeb 1
  • 2. An overview of Scalable Web Application Front-end Problem Definition Building large web applications with dozens of developers is a difficult task. Organizing the engineers around a common goal is one thing, but organizing your code so that people can work efficiently is another. Many large applications suffer from growing pains after just a few months in production due to poorly designed JavaScript with unclear upgrade and extension paths. Scalable JavaScript Application Framework Yahoo! home page engineer Nicholas Zakas1 , author of Professional JavaScript for Web Developers, introduced front-end architecture for complex, modular web applications with significant JavaScript elements. 1 nczonline.net 2 Figure 1: Scalable JavaScript Application Architecture by N. Zakas
  • 3. Module An independent unit of functionality that is part of the total structure of a web application. Web application modules consist of HTML, CSS and JavaScript. Module rules • Any single module should be able to live on its own • Loose coupling allows you to make changes to one module without affecting the others • Each module has its own sandbox ◦ An interface with which the module can interact to ensure loose coupling • Modules have limited knowledge and only know the sandbox ◦ Each module knows about their sandbox and that's it The rest of the architecture doesn't exist to them. • Only call your own methods or those on the sandbox • Don't access DOM elements outside of your box • Don't access non-native global objects • Anything else you need, ask the sandbox • Don't create global objects • Don't directly reference other modules • Modules must stay within their own sandboxes ◦ No matter how restrictive or uncomfortable it may seem Sandbox The sandbox ensures a consistent interface. Modules can rely on the methods to always be there. The sandbox also acts like a security guard. It knows what the modules are allowed to access and do on the framework. Sandbox jobs • Consistency • Security • Communication 3
  • 4. Application Core The application core manages modules. The application core tells a module when it should initialize and when it should shutdown. Also, it manages communication between modules. The application core handles errors. It uses available information to determine best course of action. Application core jobs • Manage module lifecycle • Enable inter-module communication • General error handling • Be extensible by plugins Mediator The application core handles the messages by using Mediator class. Plugins Plugins augment the capabilities of the core to keep it relevant and useful. Anything built for extension can never be obsolete. What plugins can be created • Error handling • Ajax communication • New module capabilities • General utilities • Anything! Base Library The base library provides basic functionality. Most applications are too tightly coupled to the base library. Developers get upset when they can't touch the base library. Ideally, only the application core has any idea what base library is being used. 4
  • 5. Base library jobs • Browser normalization • General purpose utilities ◦ Parsers/Serializers for XML, JSON, etc. ◦ Object manipulation ◦ DOM manipulation ◦ Ajax communication • Provide low-level extensibility Advantages • Multiple different applications can be created with the same framework. • Each part can be tested separately 5
  • 6. What's “scaleApp”? scaleApp2 is a tiny JavaScript framework for scalable JavaScript Applications. The framework allows you to easily create complex web applications. scaleApp is based on a decoupled, event-driven architecture that is inspired by the talk of Nicholas C. Zakas - "Scalable JavaScript Application Architecture". Quick start using “scaleApp”? Link scaleApp.min.js in your HTML file: <script src="scaleApp.min.js"></script> Create a core First of all create a new core instance: var core = new scaleApp.Core(); Register modules core.register( "myModuleId", function( sandbox ){ return { init: function(){ /*...*/ }, destroy: function(){ /*...*/ } }; }); As you can see the module is a function that takes the sandbox as a parameter and returns an object that has two functions init and destroy (the latter is optional). Of course your module can be any usual class with those two functions. var MyGreatModule = function(sandbox){ return { 2 http://scaleapp.org 6
  • 7. init: function(){ alert("Hello world!"); } destroy: function(){ alert("Bye bye!"); } }; }; core.register("myGreatModule", MyGreatModule); The init function is called by the framework when the module is supposed to start. The destroy function is called when the module has to shut down. Start modules After your modules are registered, start your modules: core .start( "myModuleId" ) .start( "anOtherModule", function(err){ // 'anOtherModule' is running now }); Stopping It's obvious: core.stop("moduleB"); core.stop(); // stops all running instances Publish/Subscribe If the module needs to communicate with others, you can use the emit and on methods. 7
  • 8. Emit The emit function takes three parameters whereas the last one is optional: • topic: the channel name you want to emit to • data: the data itself • cb: callback method The emit function is accessible through the sandbox: sandbox.emit( "myEventTopic", myData ); On A message handler could look like this: var messageHandler = function( data, topic ){ switch( topic ){ case "somethingHappend": sandbox.emit( "myEventTopic", processData(data) ); break; case "aNiceTopic": justProcess( data ); break; } }; … and it can listen to one or more channels: sub1 = sandbox.on( "somethingHappend", messageHandler ); sub2 = sandbox.on( "aNiceTopic", messageHandler ); 8
  • 9. Attach and Detach A subscription can be detached and attached again: sub.detach(); // don't listen any more sub.attach(); // receive upcoming messages Unsubscribe You can unsubscribe a function from channel: sandbox.off("a-channel", callback); And you can remove a callback function from all channels: sandbox.off(callback); Or remove all subscriptions from a channel: sandbox.off("channelName"); 9