56
Mastering Large Scale JavaScript Applications Fabian Jakobs

Masterin Large Scale Java Script Applications

Embed Size (px)

DESCRIPTION

Writing large desktop-like web applications is a challenge. Adapting such an application to different markets, languages or brands is even more of a challenge. This talk shows how the open source JavaScript framework qooxdoo can be leveraged to build such a rich internet application. As a real-life example the free web mail client gmx.com is used. This talk discusses the development model, customization and deployment of such an application. Learn how JavaScript applications of this size and complexity are fundamentally different from classic web applications, and what issues come up when building fast, multi-language, multi-brand JavaScript applications.

Citation preview

Page 1: Masterin Large Scale Java Script Applications

Mastering Large Scale JavaScript Applications

Fabian Jakobs

Page 2: Masterin Large Scale Java Script Applications

About

• Senior JavaScript Developer at 1&1

• core developer since 2006

@fjakobs

Page 3: Masterin Large Scale Java Script Applications

Man With Two Hats

Page 4: Masterin Large Scale Java Script Applications

Framework Application

Page 5: Masterin Large Scale Java Script Applications

Large ScaleJavaScript Applications

Page 6: Masterin Large Scale Java Script Applications

JavaScript Application

Page 7: Masterin Large Scale Java Script Applications

JavaScript Application

Page 8: Masterin Large Scale Java Script Applications

JavaScript Application

Page 9: Masterin Large Scale Java Script Applications

JavaScript Application

Page 10: Masterin Large Scale Java Script Applications

JavaScript Application

• Single Page Application

• Client Logic in JavaScript

• Client-Server Communication with AJAX calls

Page 11: Masterin Large Scale Java Script Applications

Large Scale

• Complexity and Size of JavaScript code

• ~ 150,000 LOC

• ~ 1000 Classes

Page 12: Masterin Large Scale Java Script Applications
Page 13: Masterin Large Scale Java Script Applications

• Rich Web Mail Application

• Pure JavaScript Client

• Backend Communication with Ajax calls

• Based on qooxdoo

Page 14: Masterin Large Scale Java Script Applications

• Client-side JavaScript Framework

• Cross-browser web applications

• Open Source

Page 15: Masterin Large Scale Java Script Applications

JavaScript isn‘t made for this

Page 16: Masterin Large Scale Java Script Applications

JavaScript isn‘t made for this

• No package mechanism

• By default everything is in the global namespace

• Only basic building blocks for OOP

• Tooling still sucks

Page 17: Masterin Large Scale Java Script Applications

Everybody puts a layer on top

• GWT covers JavaScript with Java

• Cappuchino uses Objective-J

• Adobe invented ActionScript

• Everyone else uses (different) meta object systems written in JavaScript

Page 18: Masterin Large Scale Java Script Applications

qooxdoo OOPqx.Class.define("demo.Person", { extend : qx.core.Object,

construct : function(firstName, lastName) { this.base(arguments); this._firstName = firstName; this._lastName = lastName; },

members : { getFullName : function() { return this._firstName + " " + this._lastName; } }});

Page 19: Masterin Large Scale Java Script Applications

Tooling

Page 20: Masterin Large Scale Java Script Applications

Tooling

Linker

Lint

IDE Support

Auto Completion

Unit Testing

Code Coverage

API Doc

Page 21: Masterin Large Scale Java Script Applications

Tooling dilemma

• Different OOP syntax makes generic tooling hard

• Tools often depend in certain Framework features

• Don‘t just look at the widgets, look at the development tools as well

Page 22: Masterin Large Scale Java Script Applications

Find the Right Level of Abstraction

Page 23: Masterin Large Scale Java Script Applications

Desktop Like Web Applications Need

Desktop Abstractions

• Widgets

• Layout Manager

• Themes

• DOM Nodes

• CSS

• Browser Bugs

vs

Page 24: Masterin Large Scale Java Script Applications

Abstractions

Core (JavaScript OOP)

BOM (Cross Browser Code)

UI Core(Rendering Engine)

Base Widgets

Application Components

Custom Widgets

Framework

Application

Page 25: Masterin Large Scale Java Script Applications

Desktop StyleDevelopment Model

// Create a buttonvar button = new qx.ui.form.Button("First Button", "demo/browser.png");

// Add button to container at fixed coordinatescontainer.add(button, {left: 100, top: 50});

// Add an event listenerbutton.addListener("execute", function(e) { alert("Hello World!");});

Page 26: Masterin Large Scale Java Script Applications

Leaky Abstractions

• Emulated behavior may be slower

• e.g. Canvas wrapper for IE

• For advanced tasks its essential to know the lower layers

• CSS, HMTL, DOM knowledge is still needed

Page 27: Masterin Large Scale Java Script Applications

Styling

Page 28: Masterin Large Scale Java Script Applications

StylingNo OS clone! No default theme Everything Custom!

Page 29: Masterin Large Scale Java Script Applications
Page 30: Masterin Large Scale Java Script Applications

Not EveryoneSpeaks German

Page 31: Masterin Large Scale Java Script Applications

i18n

Page 32: Masterin Large Scale Java Script Applications

i18n

Page 33: Masterin Large Scale Java Script Applications

i18n

Page 34: Masterin Large Scale Java Script Applications

i18n in qooxdoo

• Standards

• gettext

• CLDR

• good external tooling

• known by professional translators

this button = var qx.ui.form.Button(this.tr("Hello World!"));

Page 35: Masterin Large Scale Java Script Applications

Performance

Page 36: Masterin Large Scale Java Script Applications

Our Bottlenecks

• Startup time

• Widget creation

• Table scroll performance

Page 37: Masterin Large Scale Java Script Applications

Startup Time

• Combine

• Compress

• Cache

• On demand

The 3Cs + O

Page 38: Masterin Large Scale Java Script Applications

Combine

• reduce number of requests

• combine

• JavaScript files

• CSS

• Images

PNGPNGJSJS

PNGJS

Page 39: Masterin Large Scale Java Script Applications

Compress

• optipng et el for images

• compress JavaScript

• serve with gzip

Page 40: Masterin Large Scale Java Script Applications

Compress JavaScript

Page 41: Masterin Large Scale Java Script Applications

Cache

• Serve static files with „cache forever“

• Increase version number if content changes

• Use Image servers

Page 42: Masterin Large Scale Java Script Applications

On Demand

• Defer operations

• Load Code on demand

• Load Data on demand

• Render UI on demand

Page 43: Masterin Large Scale Java Script Applications

On Demand Code

• The initial view does not need

• Editor

• Settings

• Address book

• ...

Page 44: Masterin Large Scale Java Script Applications

On Demand Code

qx.io.PartLoader.require("settings", function(){ mailclient.ui.SettingsDialog.getInstance().open();}, this);

..."packages" : { "parts" : { "settings": { "include" : ["mailclient.ui.SettingsDialog"] } }}...

• Code

• Content

Page 45: Masterin Large Scale Java Script Applications

On Demand Data and UI

• Thousands of mails in the inbox

• Only load visible data

• Only render visible rows of the table

Page 46: Masterin Large Scale Java Script Applications

Widget Creation

• DOM operations are expensive

• Creation Widgets is expensive

• Reuse Widgets

• Share Widgets

• Pool Widgets

• Increases Complexity!

Page 47: Masterin Large Scale Java Script Applications

Reuse Widgets

pool and reuse mail folder

share mail preview among tabs

Page 48: Masterin Large Scale Java Script Applications

Clean Code

Page 49: Masterin Large Scale Java Script Applications

Decouple UI Components

Page 50: Masterin Large Scale Java Script Applications

Decouple UI Components

Message Bus

Page 51: Masterin Large Scale Java Script Applications

Code Should be Executable in Isolation

• Without rebuilding the application

• Without restarting the application

• Without a server

Page 52: Masterin Large Scale Java Script Applications

Unit Tests

Page 53: Masterin Large Scale Java Script Applications

Mini Applications

Page 54: Masterin Large Scale Java Script Applications

Summary

• Good Abstractions

• Styling

• Internationalization

• Performance

• Clean Code

Page 55: Masterin Large Scale Java Script Applications

Thank you.

Fabian Jakobs @fjakobs

<[email protected]>http://qooxdoo.org

colorstrip.gifTTHE NEW ERA OF WEB DEVELOPMENT