KEMBAR78
Writing a massive javascript app | PPTX
Writing a massive javascript app 
Hojoon Park 
Sr. Software Engineer 
LinkedIn 
www.linkedin.com/in/justindoit
2 
Over the last 3 years, 
 Single Page Application (BackboneJS, AngularJS) 
 Template System(Handlebars, Dust.LI) 
 Web Framework (SugarAPIFramework, Java Play Framework) 
 Unit Test (JasmineJS, SinonJS)
3 
Agenda 
 Web Frameworks 
 Single Page Application 
 Case Study 
 Performance Tuning 
 Demo
Avoid spaghetti code in Front-end development 
4 
 Too much copy/paste 
 Too much 3rd party recourses 
 Hard to debug the errors
5 
Web Frameworks, recommend? 
 Play 
 Spring 
 Ruby on Rails 
 Yii 
 Node.JS 
 … 
 Angular 
 Backbone 
 jQuery 
 YUI 
 Require 
 Knockout 
 Bootstrap 
 …
6 
Case Study: BackboneJS on PHP 
 Pure SPA 
 Metadata Manager 
 Data Manager
7 
Case Study: BackboneJS on Java Play 
 Hybrid Web Application 
 sbt-concat, sass compiler 
 Model Hierarchy
8 
Case Study: AngularJS on Java Play 
 Pure SPA 
 Grunt Builder 
 Less compiler by Grunt
9 
What is SPA (Single Page Application)? 
 Routing 
 Angular RouteProvider / Backbone Router 
 MVC Framework 
 Models as the single source 
 Views observe model changes 
 Minimized DOM dependent-code 
 Asset Packaging
10 
SPA (Single Page Application) 
Cons. Pros. 
SEO Optimization 
No longer server side loading 
(Read data thru AJAX) 
Higher Risk, Higher Reward 
(Memory Leak) 
Client/Server code partitioning 
Large File Size No Page Refresh
11 
Consideration for SPA 
 Resources/Assets Management 
 JS/CSS compressor 
 Template compiler 
 Additional: LESS/SASS compiler
12 
Why Asset Management is important? 
 Continuously growing JS/CSS resources 
 Duplicated JS files / version inconsistency
13 
Sync vs. Async 
Sync Async 
Controller 
Web framework 
(Compiler plugin, 
AssetManager) 
Front-end Tools 
(Require.JS, Inject.JS) 
Pros. No delay on click Lazy Load 
Cons. Longer loading time Loading on click
14 
Anatomy: Directory(1) 
 By Resource Type
15 
Anatomy: Directory(2) 
 By Feature
16 
Asset Packaging: Play Framework 
 sbt-concat plugin 
 JavascriptMinifierCompiler
17 
Asset Packaging: Yii Framework 
 AssetManager
18 
Build asset packages without web framework 
 Resources/Assets Management 
 JS/CSS compressor 
 Template compiler 
 Additional: LESS/SASS compiler 
Build System 
Tool 
Bower 
Package 
Manager
19 
Metadata Manager 
 Sort the dependent modules 
DashableListView 
extends: ListView 
FlexListView 
extends: ListView 
ListView 
RecordListView 
Extends: FlexListView 
ListView 
DashableListView 
extends: ListView 
FlexListView 
extends: ListView 
RecordListView 
Extends: FlexListView
/** 
* Sorts components in the order they should be declared as classes. This is required since a parent 
* widget class must likewise be declared before a child that depends on it. 
* @param {String} type Metadata type e.g. field, view. layout 
* @param {Array} components List of modules 
* @param {String} module Module name 
* @return {Array} Sorted components 
*/ 
_sortControllers : function(type, components, module) { 
var updated = {}, nameMap = {}, entries = {}, 
updateWeights = function(entry){ 
var controller = entry.controller; 
// Here we decrement the weight of any extended components. Note, that if sorting platform 
// specific components (e.g. portal), and one "extends from" a base component, that parent 
// will have already been declared since _sortControllers first gets called with base components 
if (_.isObject(controller) && _.isString(controller.extendsFrom) && 
entries[controller.extendsFrom] && !updated[controller.extendsFrom]) 
{ 
// Negative weights as we want to load those first 
entries[controller.extendsFrom].weight--; 
updated[controller.extendsFrom] = true; 
updateWeights(entries[controller.extendsFrom]); 
} 
}; 
// Start by creating a mapping from short name to final class name and precompiling all the controllers that are strings 
_.each(components, function(entry, name) { 
if (entry.controller) { 
var controller = entry.controller, 
className = (module || "") + app.utils.capitalizeHyphenated(name) + app.utils.capitalize(type); 
nameMap[className] = name; 
20 
Metadata Manager: cont. 
 Implementation
Great Design patterns are reusable, modular 
expressions of what’s going on in your code. 
They allow you to communicate to other 
developers simply by the way you code, 
in addition to being easily maintainable 
themselves 
21 
Why Patterns?
22 
Software design patterns 
 Factory 
 Singleton 
 MVC 
 Strongly OOP 
 Mixin 
 Event Driven
23 
Object Oriented Programming 
 Code Reuse and recycling 
 Design Benefits 
 More features, 
same amount of time 
ListView 
FlexListView 
SubPanelListView 
DashableListView 
SelectionListView RecordListView
ListView MergeDuplicateView 
Tooltip 
Mixin pool 
24 
Decorator: Mixin (plugin) 
RecordListView 
extends: ListView 
ErrorDecoration 
Editable 
MergeDuplicates 
CreateView 
Audit 
FindDuplicates 
Timeago 
ActivityStreamView
25 
BackboneJS: Life-cycle of View Component 
Initialize Bind events 
Render 
template 
Unbind 
events 
Dispose 
Register Watchers 
Trigger 
Unregister
26 
AngularJS: Life-cycle of scope 
Creation 
Watcher 
registration 
Model 
mutation 
Mutation 
observation 
Scope 
destruction
He who binds himself to a joy 
Does the winged life destroy; 
But he who kisses the joy as it flies 
Lives in eternity's sun rise. 
27 
William Blake
28 
Performance tuning 
 Remove duplicate listeners 
 Watcher optimization 
 Backbone: _events stack 
 Angular: $__watchers in $digest cycle 
 How many watchers will be incurred?
29 
Don’t blame browser
30 
Memory Management 
 Dispose safe 
Initialize Bind events 
Render 
Dispose Unbind events 
Register Watchers 
Trigger 
Unregister
31 
Memory Management: cont. 
 Catch while unit testing
32 
Debugging 
 Firebug 
 Chrome developer tool 
 Network filtering 
 Recording 
 Profiler 
 Local Storage in resources tab
33 
Unit Test 
 Jasmine, Karma, Sinon 
 Travis CI 
 Selenium WebDriver
34 
Demo

Writing a massive javascript app

  • 1.
    Writing a massivejavascript app Hojoon Park Sr. Software Engineer LinkedIn www.linkedin.com/in/justindoit
  • 2.
    2 Over thelast 3 years,  Single Page Application (BackboneJS, AngularJS)  Template System(Handlebars, Dust.LI)  Web Framework (SugarAPIFramework, Java Play Framework)  Unit Test (JasmineJS, SinonJS)
  • 3.
    3 Agenda Web Frameworks  Single Page Application  Case Study  Performance Tuning  Demo
  • 4.
    Avoid spaghetti codein Front-end development 4  Too much copy/paste  Too much 3rd party recourses  Hard to debug the errors
  • 5.
    5 Web Frameworks,recommend?  Play  Spring  Ruby on Rails  Yii  Node.JS  …  Angular  Backbone  jQuery  YUI  Require  Knockout  Bootstrap  …
  • 6.
    6 Case Study:BackboneJS on PHP  Pure SPA  Metadata Manager  Data Manager
  • 7.
    7 Case Study:BackboneJS on Java Play  Hybrid Web Application  sbt-concat, sass compiler  Model Hierarchy
  • 8.
    8 Case Study:AngularJS on Java Play  Pure SPA  Grunt Builder  Less compiler by Grunt
  • 9.
    9 What isSPA (Single Page Application)?  Routing  Angular RouteProvider / Backbone Router  MVC Framework  Models as the single source  Views observe model changes  Minimized DOM dependent-code  Asset Packaging
  • 10.
    10 SPA (SinglePage Application) Cons. Pros. SEO Optimization No longer server side loading (Read data thru AJAX) Higher Risk, Higher Reward (Memory Leak) Client/Server code partitioning Large File Size No Page Refresh
  • 11.
    11 Consideration forSPA  Resources/Assets Management  JS/CSS compressor  Template compiler  Additional: LESS/SASS compiler
  • 12.
    12 Why AssetManagement is important?  Continuously growing JS/CSS resources  Duplicated JS files / version inconsistency
  • 13.
    13 Sync vs.Async Sync Async Controller Web framework (Compiler plugin, AssetManager) Front-end Tools (Require.JS, Inject.JS) Pros. No delay on click Lazy Load Cons. Longer loading time Loading on click
  • 14.
    14 Anatomy: Directory(1)  By Resource Type
  • 15.
    15 Anatomy: Directory(2)  By Feature
  • 16.
    16 Asset Packaging:Play Framework  sbt-concat plugin  JavascriptMinifierCompiler
  • 17.
    17 Asset Packaging:Yii Framework  AssetManager
  • 18.
    18 Build assetpackages without web framework  Resources/Assets Management  JS/CSS compressor  Template compiler  Additional: LESS/SASS compiler Build System Tool Bower Package Manager
  • 19.
    19 Metadata Manager  Sort the dependent modules DashableListView extends: ListView FlexListView extends: ListView ListView RecordListView Extends: FlexListView ListView DashableListView extends: ListView FlexListView extends: ListView RecordListView Extends: FlexListView
  • 20.
    /** * Sortscomponents in the order they should be declared as classes. This is required since a parent * widget class must likewise be declared before a child that depends on it. * @param {String} type Metadata type e.g. field, view. layout * @param {Array} components List of modules * @param {String} module Module name * @return {Array} Sorted components */ _sortControllers : function(type, components, module) { var updated = {}, nameMap = {}, entries = {}, updateWeights = function(entry){ var controller = entry.controller; // Here we decrement the weight of any extended components. Note, that if sorting platform // specific components (e.g. portal), and one "extends from" a base component, that parent // will have already been declared since _sortControllers first gets called with base components if (_.isObject(controller) && _.isString(controller.extendsFrom) && entries[controller.extendsFrom] && !updated[controller.extendsFrom]) { // Negative weights as we want to load those first entries[controller.extendsFrom].weight--; updated[controller.extendsFrom] = true; updateWeights(entries[controller.extendsFrom]); } }; // Start by creating a mapping from short name to final class name and precompiling all the controllers that are strings _.each(components, function(entry, name) { if (entry.controller) { var controller = entry.controller, className = (module || "") + app.utils.capitalizeHyphenated(name) + app.utils.capitalize(type); nameMap[className] = name; 20 Metadata Manager: cont.  Implementation
  • 21.
    Great Design patternsare reusable, modular expressions of what’s going on in your code. They allow you to communicate to other developers simply by the way you code, in addition to being easily maintainable themselves 21 Why Patterns?
  • 22.
    22 Software designpatterns  Factory  Singleton  MVC  Strongly OOP  Mixin  Event Driven
  • 23.
    23 Object OrientedProgramming  Code Reuse and recycling  Design Benefits  More features, same amount of time ListView FlexListView SubPanelListView DashableListView SelectionListView RecordListView
  • 24.
    ListView MergeDuplicateView Tooltip Mixin pool 24 Decorator: Mixin (plugin) RecordListView extends: ListView ErrorDecoration Editable MergeDuplicates CreateView Audit FindDuplicates Timeago ActivityStreamView
  • 25.
    25 BackboneJS: Life-cycleof View Component Initialize Bind events Render template Unbind events Dispose Register Watchers Trigger Unregister
  • 26.
    26 AngularJS: Life-cycleof scope Creation Watcher registration Model mutation Mutation observation Scope destruction
  • 27.
    He who bindshimself to a joy Does the winged life destroy; But he who kisses the joy as it flies Lives in eternity's sun rise. 27 William Blake
  • 28.
    28 Performance tuning  Remove duplicate listeners  Watcher optimization  Backbone: _events stack  Angular: $__watchers in $digest cycle  How many watchers will be incurred?
  • 29.
  • 30.
    30 Memory Management  Dispose safe Initialize Bind events Render Dispose Unbind events Register Watchers Trigger Unregister
  • 31.
    31 Memory Management:cont.  Catch while unit testing
  • 32.
    32 Debugging Firebug  Chrome developer tool  Network filtering  Recording  Profiler  Local Storage in resources tab
  • 33.
    33 Unit Test  Jasmine, Karma, Sinon  Travis CI  Selenium WebDriver
  • 34.

Editor's Notes

  • #3 SugarCRM에서 BackboneJS, PHP API Framework을 이용하여 싱글페이지어플리케이션을 개발
  • #4 백엔드 및 프론트엔드 프레임워크 구성 Single Page Application Resources/Assets Management What is MVC Front-end Framework Case Study: AngularJS Case Study: BackboneJS Performance Tuning Debugging Memory Leak Demo
  • #6 좋은것은 없다 다만 MVC 패턴이 잘갖춰진 프레임워크를 고르자
  • #10 Asset Packaging (or more descriptively, packaging code for the browser)
  • #12 싱글페이지개발에선 템플릿엔진이 필수
  • #17 중복되는 파일을 줄이고 다운로드하는 파일 사이즈를 줄이는 방법
  • #20 데모와 함께 소개
  • #21 데모와 함께 소개 이제 체계적인 코드를 생성할 수 있는 준비가 끝났기때문에 설계에 대해서 깊게 알아보도록 합니다.
  • #22 A joy is not to be attached deeply cause attachement brings suffer
  • #23 JS 경우 event based async 랭귀지이기때문에 설계가 중요 Front-end also follows software design patterns
  • #24 데모와 함께 소개
  • #26 Angular같은경우 $watch사용에 주의
  • #27 Angular같은경우 $watch사용에 주의
  • #28 A joy is not to be attached deeply cause attachement brings suffer
  • #31 크롬 시크릿(incognito) 모드로 체크할것!
  • #32 크롬 시크릿(incognito) 모드로 체크할것!
  • #35 Oauth-token