SlideShare a Scribd company logo
1 of 49
Download to read offline
Trimming The Cruft:
                Getting the most of your bits




    Peter Higgins (dante)
  Dojo Toolkit Project Lead
DevNexus: March 10 + 11, 2009
Me.
What is Dojo?

• A JavaScript Toolkit
  - Light-weight Base.
  - Use at will framework.
• 100 - point Open Source
  - Clean IP
  - Open Cycle
• Developer Tools
The History of Dojo
      (cli notes version)
Alex Russell
“netwindows”
A Foundation.
Unifying a DHTML landscape
A Team.
Maintaining a vision.
Dojo, Brie y.
Plain JavaScript

 • JavaScript should have:
    - dojo.indexOf / forEach / map / lter
    - hitch / partial
    - declare / delegate / mixin / extend
Package / Module Loading

• dojo.require(“some.module”)
• dojo.addOnLoad(function(){ ... })
• dojo.registerModulePath(“my”, “../../my/”)
• dojo.require(“my.code”)
• dojo.provide(“my.code”)
Events, Ajax, FX, DOM

• dojo.connect(node, “onclick”, function(){ });
• dojo.connect(obj, “custom”, obj, “sync”);
• dojo.xhrPost({ form:”login”, load:function(dat){}});
• dojo.xhrGet({ url:”foo.txt”, load:function(){ } });
• dojo.anim(node, { width:200 });
• dojo.fadeIn({ node: node }).play();
• dojo.style(n, “height”, “50px”);
• dojo.place(“<p>Hi</p>”, dojo.body());
CSS Selectors

• dojo.query(“ul > li”).addClass(“listy”);
• dojo.query(“a”).onclick(function(){ });
• dojo.query(“tr td + td”).forEach(function(n){ });
• dojo.query(“.someClass”).map(function(n){ .. });
• dojo.NodeList.prototype / dojo.extend
Flexible Dynamic Language

 // confuse people
 (function(foo){
      var f = foo, fid = f.byId;
      f.require(“my.code”);
      f.addOnLoad(function(){
         new my.Thinger({ node: fid(‘bar’) });
      });
 })(dojo);

 // bling
 (function(d, $){
        $(“.class”).onclick(function(){ });
 })(dojo, dojo.query);
Optimization Fundamentals
Separate Assets.
Scripts are Blocking,
   Synchronous.
<head>
  <script src=”dojo.js”></script>
  <script>/* code in dojo.js ready */</script>
</head>
<body><p>Lots of DOM</p></body>

                             vs:

<body>
  <p>Lots of DOM</p>
  <script src=”dojo.js”></script>
  <script>/* code in dojo.js ready */</script>
</body>
Multiple Inline Scripts
Know request limits.
gzip “required”.

 • Incredible, exponential savings.
    - Bene ts from patterns
 • 9 / 10 Major Browsers Support
CSS is “async”

 • No reliable “onload”
 • Put requests rst
 • Limit @import
De ne “ready”

• DOMContentLoaded & window.onload
• CSS, JS and Image resources
  - required or deferred?
  - preloaded and cached.
Content Distribution (CDN)
CDN Bene ts

• Shared Resources
  - Cached, common, static
• Public vs Private
• Headers / Cookies
• Beating request limits
Client Considerations
       (on the wire cost)
JSON vs XML
JavaScript is Fast.
The DOM isn’t.
DOM & CSS

• Size
• Complexity
• Manipulation
  - Avoiding loops
  - working outside the DOM
• Server vs Client
Events

• Delegation
   - Normalization
     - Bubbles, Cancels
• Invention
   - mouseenter/mouseleave
   - onDijitClick
Code Considerations
     (also on the client)
Modularity. Inheritance.
More on Packages


 // the package:
 dojo.provide(“my.Module”); // my/Module.js
 dojo.require(“my._ClassBase”); // my/_ClassBase.js
 dojo.declare(“my.Module”, my._ClassBase, {});

 // the code:
 dojo.require(“my.Module”);
 dojo.addOnLoad(function(){
     new my.Module();
 });
Mix-in Patterns
Arguments, etc.


 // function signatures with defaults
 my.func = function(args){
    var opts = dojo.mixin({
        prop:”foo”
    }, args||{});
    console.log(opts.prop);
 }

 my.func(); // “foo”
 my.func({ prop:”bar” }); // “bar”
Ambiguous Constructors


 dojo.declare(“some.Thing”, null, {
     opt:”a-default”,
     constructor: function(args){
         dojo.mixin(this, args);
     }
 });

 var a = new some.Thing(), b = new some.Thing({ opt:”x” });
 a.opt == “a-default”
 b.opt == “x”
DRY


 my.turnIt = function(dir){
    // if 1, go next. -1, go left.
 }

 var next = dojo.partial(my.turnIt, 1),
     prev = dojo.partial(my.turnIt, -1);

 // later
 dojo.query(“.nextbutton”).onclick(next);
Dual Service Functions

 my.func = function(node, args){
   node = dojo.byId(node); // Sting|DomNode
   /* do something to node */
 }

 dojo.extend(dojo.NodeList, {
    func: dojo.NodeList._mapAsForEach(“func”, my)
 });

 // run one, run all
 my.func(“someId”, { opts:true });
 dojo.query(“.someNodes”).func({ opts:true })
Mini cation
To consider:

 • YUI / ShrinkSafe / jsmin / packer
   - variables, whitespace
   - preserve public APIs
 • Micro vs. Premature optimizations
   - For GZIP
   - For ShrinkSafe
Dojo Build System
All-in-One

• Works transparently with Package System
• Group modules into layers
• Concatenate CSS into layers
• Layer & File mini cation
   - Comments, Whitespace, newlines ...
Special Builds

 • Stubs (6k dojo.js)
 • Base++ (dojo.js with modules)
 • Cross-Domain
 • WebKit Mobile
 • plugd
 • Maven
Build Options

• #ifDef
   - WebKit Mobile
• stripConsole
• internStrings
Questions?
Me, Again.
    dante@dojotoolkit.org
 http://twitter.com/phiggins
http://higginsforpresident.net/

More Related Content

What's hot

Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Arian Gutierrez
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015Jeongkyu Shin
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.jsWebsecurify
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
コミュニケーションとしてのコード
コミュニケーションとしてのコードコミュニケーションとしてのコード
コミュニケーションとしてのコードAtsushi Shibata
 
7주 JavaScript 실습
7주 JavaScript 실습7주 JavaScript 실습
7주 JavaScript 실습지수 윤
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mateCodemotion
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
MongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲームMongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲームSuguru Namura
 
Ember background basics
Ember background basicsEmber background basics
Ember background basicsPhilipp Fehre
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenDevDay Dresden
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBSqreen
 
PuppetCamp SEA 1 - Version Control with Puppet
PuppetCamp SEA 1 - Version Control with PuppetPuppetCamp SEA 1 - Version Control with Puppet
PuppetCamp SEA 1 - Version Control with PuppetWalter Heck
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js PlatformDomenic Denicola
 

What's hot (20)

Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Couchdb w Ruby'm
Couchdb w Ruby'mCouchdb w Ruby'm
Couchdb w Ruby'm
 
コミュニケーションとしてのコード
コミュニケーションとしてのコードコミュニケーションとしてのコード
コミュニケーションとしてのコード
 
7주 JavaScript 실습
7주 JavaScript 실습7주 JavaScript 실습
7주 JavaScript 실습
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mate
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 
MongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲームMongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲーム
 
Couchdb
CouchdbCouchdb
Couchdb
 
Ember background basics
Ember background basicsEmber background basics
Ember background basics
 
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzenAndreas Roth - GraphQL erfolgreich im Backend einsetzen
Andreas Roth - GraphQL erfolgreich im Backend einsetzen
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
 
Indexing
IndexingIndexing
Indexing
 
What is nodejs
What is nodejsWhat is nodejs
What is nodejs
 
PuppetCamp SEA 1 - Version Control with Puppet
PuppetCamp SEA 1 - Version Control with PuppetPuppetCamp SEA 1 - Version Control with Puppet
PuppetCamp SEA 1 - Version Control with Puppet
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
 

Similar to Trimming The Cruft

The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build Systemklipstein
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...Mathias Bynens
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQueryBastian Feder
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJSSylvain Zimmer
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode ObjectsEWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode ObjectsRob Tweed
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
 

Similar to Trimming The Cruft (20)

dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build System
 
Txjs
TxjsTxjs
Txjs
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...How DRY impacts JavaScript performance // Faster JavaScript execution for the...
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQuery
 
dojo.things()
dojo.things()dojo.things()
dojo.things()
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Zero To Dojo
Zero To DojoZero To Dojo
Zero To Dojo
 
Using Dojo
Using DojoUsing Dojo
Using Dojo
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode ObjectsEWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
EWD 3 Training Course Part 22: Traversing Documents using DocumentNode Objects
 
YUI 3
YUI 3YUI 3
YUI 3
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 

Recently uploaded

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

Trimming The Cruft

  • 1. Trimming The Cruft: Getting the most of your bits Peter Higgins (dante) Dojo Toolkit Project Lead DevNexus: March 10 + 11, 2009
  • 2. Me.
  • 3.
  • 4. What is Dojo? • A JavaScript Toolkit - Light-weight Base. - Use at will framework. • 100 - point Open Source - Clean IP - Open Cycle • Developer Tools
  • 5. The History of Dojo (cli notes version)
  • 8. Unifying a DHTML landscape
  • 12. Plain JavaScript • JavaScript should have: - dojo.indexOf / forEach / map / lter - hitch / partial - declare / delegate / mixin / extend
  • 13. Package / Module Loading • dojo.require(“some.module”) • dojo.addOnLoad(function(){ ... }) • dojo.registerModulePath(“my”, “../../my/”) • dojo.require(“my.code”) • dojo.provide(“my.code”)
  • 14. Events, Ajax, FX, DOM • dojo.connect(node, “onclick”, function(){ }); • dojo.connect(obj, “custom”, obj, “sync”); • dojo.xhrPost({ form:”login”, load:function(dat){}}); • dojo.xhrGet({ url:”foo.txt”, load:function(){ } }); • dojo.anim(node, { width:200 }); • dojo.fadeIn({ node: node }).play(); • dojo.style(n, “height”, “50px”); • dojo.place(“<p>Hi</p>”, dojo.body());
  • 15. CSS Selectors • dojo.query(“ul > li”).addClass(“listy”); • dojo.query(“a”).onclick(function(){ }); • dojo.query(“tr td + td”).forEach(function(n){ }); • dojo.query(“.someClass”).map(function(n){ .. }); • dojo.NodeList.prototype / dojo.extend
  • 16. Flexible Dynamic Language // confuse people (function(foo){ var f = foo, fid = f.byId; f.require(“my.code”); f.addOnLoad(function(){ new my.Thinger({ node: fid(‘bar’) }); }); })(dojo); // bling (function(d, $){ $(“.class”).onclick(function(){ }); })(dojo, dojo.query);
  • 19. Scripts are Blocking, Synchronous.
  • 20. <head> <script src=”dojo.js”></script> <script>/* code in dojo.js ready */</script> </head> <body><p>Lots of DOM</p></body> vs: <body> <p>Lots of DOM</p> <script src=”dojo.js”></script> <script>/* code in dojo.js ready */</script> </body>
  • 23. gzip “required”. • Incredible, exponential savings. - Bene ts from patterns • 9 / 10 Major Browsers Support
  • 24. CSS is “async” • No reliable “onload” • Put requests rst • Limit @import
  • 25. De ne “ready” • DOMContentLoaded & window.onload • CSS, JS and Image resources - required or deferred? - preloaded and cached.
  • 27. CDN Bene ts • Shared Resources - Cached, common, static • Public vs Private • Headers / Cookies • Beating request limits
  • 28. Client Considerations (on the wire cost)
  • 32. DOM & CSS • Size • Complexity • Manipulation - Avoiding loops - working outside the DOM • Server vs Client
  • 33. Events • Delegation - Normalization - Bubbles, Cancels • Invention - mouseenter/mouseleave - onDijitClick
  • 34. Code Considerations (also on the client)
  • 36. More on Packages // the package: dojo.provide(“my.Module”); // my/Module.js dojo.require(“my._ClassBase”); // my/_ClassBase.js dojo.declare(“my.Module”, my._ClassBase, {}); // the code: dojo.require(“my.Module”); dojo.addOnLoad(function(){ new my.Module(); });
  • 38. Arguments, etc. // function signatures with defaults my.func = function(args){ var opts = dojo.mixin({ prop:”foo” }, args||{}); console.log(opts.prop); } my.func(); // “foo” my.func({ prop:”bar” }); // “bar”
  • 39. Ambiguous Constructors dojo.declare(“some.Thing”, null, { opt:”a-default”, constructor: function(args){ dojo.mixin(this, args); } }); var a = new some.Thing(), b = new some.Thing({ opt:”x” }); a.opt == “a-default” b.opt == “x”
  • 40. DRY my.turnIt = function(dir){ // if 1, go next. -1, go left. } var next = dojo.partial(my.turnIt, 1), prev = dojo.partial(my.turnIt, -1); // later dojo.query(“.nextbutton”).onclick(next);
  • 41. Dual Service Functions my.func = function(node, args){ node = dojo.byId(node); // Sting|DomNode /* do something to node */ } dojo.extend(dojo.NodeList, { func: dojo.NodeList._mapAsForEach(“func”, my) }); // run one, run all my.func(“someId”, { opts:true }); dojo.query(“.someNodes”).func({ opts:true })
  • 43. To consider: • YUI / ShrinkSafe / jsmin / packer - variables, whitespace - preserve public APIs • Micro vs. Premature optimizations - For GZIP - For ShrinkSafe
  • 45. All-in-One • Works transparently with Package System • Group modules into layers • Concatenate CSS into layers • Layer & File mini cation - Comments, Whitespace, newlines ...
  • 46. Special Builds • Stubs (6k dojo.js) • Base++ (dojo.js with modules) • Cross-Domain • WebKit Mobile • plugd • Maven
  • 47. Build Options • #ifDef - WebKit Mobile • stripConsole • internStrings
  • 49. Me, Again. dante@dojotoolkit.org http://twitter.com/phiggins http://higginsforpresident.net/