SlideShare a Scribd company logo
1 of 52
Dirk Ginader | Yahoo! Inc.

Javascript done right




                             @ginader
What is “good” Javascript?

• From a User Perspective?
What is “good” Javascript?

• From a User Perspective:
  – THEY DON’T CARE!*




                    *as long as it works...
What is “good” Javascript?

• From a Developer Perspective?
What is “good” Javascript?

• From a Developer Perspective:
  –   understandable
  –   reusable
  –   extensible
  –   optimized
  –   secure
  –   internationalized
  –   optional
  –   accessible
Understandable

• don’t be “too clever”
Understandable

• don’t be “too clever”
Understandable

• not everybody understands:
  – Ternary:
    • var d = (x < m) ? 'l' : 'r';
Understandable

• not everybody understands:
  – Regex:
    • ^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+-+)|([A-Za-
      z0-9]+.+)|([A-Za-z0-9]+++))*[A-Za-
      z0-9]+@((w+-+)|(w+.))*w{1,63}.[a-zA-Z]
      {2,6}$
Understandable

• not everybody understands:
  – Shakespeare:
    • /(bb|[^b]{2})/
Understandable

• If there’s no good way around
  cleverness then:
  – good naming
  – documentation
for more WTF check

• http://wtfjs.com
Understandable -> Documented

• Writing Docs isn’t fun
• Reading Code you wrote 5 years ago
  and didn’t document is worse...
• Reading undocumented code
  someone else wrote even more so...
Understandable -> Documented

• use clear variable and function
  names:
  – a = b(c) // Whut?
  – user = getUserOfProduct(productId) // Alright!

• good comments
  – // IE seems to break here...
  – // dirty hack. This must never go live!
  – // this works. No idea why. Better don’t touch.
Understandable -> Documented

• exceptionally good comments:
  – YUI Doc: http://developer.yahoo.com/
    yui/yuidoc/
  – creates the YUI API Dos automatically
  – simple Javadoc syntax
   /**
   * short description
   * @method methodName
   * @param {bool}
   * @returm {type}
   */
Understandable -> Documented

• YUI Doc now even prettier thanks to
  Carlo & Dana:
  http://www.yuiblog.com/blog/
  2010/10/01/yuidoc-dana-theme/
Understandable -> Structured

• HTML
  – Markup
• CSS
  – Design
• Javascript
  – Interaction
Understandable -> Structured

• CSS for Javascript
  – <script>
       document.documentElement.className += ' js';
    </script>
    <style>
    .module{
        /* with JS */
    }
    .js .module{
        /* without JS */
    }
    </style>
Understandable -> Structured

• HTML for Javascript
  – Mustache Templating Partials for
    Ajax content
  – /partials/login_success.html
  – Hello {{user_name}}
    You have sucesfully registered
    Your currently have {{user_points}} points
  – {
        user_name   : “dude”,
        user_points : 123
   }

  – http://mustache.github.com/
Reusable

• find patterns
• largest common denominator
• when you’re writing a new
  dropdown menu every month
  something is very wrong...
• write ONE dropdown menu and keep
  making it better
Reusable

• open source != “I’m giving it away
  for free”
• open source == “I get free testers,
  co-developers, fame and fortune”
• github is full of excellent code
• “FORK OFF” - make it better!
• a plugin for an existing library is a
  great start
Reusable

• How do you write Javascript?
  – jQuery, YUI and alike?
  – all “pure”?
Reusable

• You’re using and understand just
  one Javascript Framework?
  – learn Javascript!
  – look under the hood
  – understand Errors
Reusable

• You don’t use Frameworks?
  – you should!
Reusable

• Javascript Frameworks/Libraries
  help to
  –   not reinvent the wheel all over again
  –   keep Code fresh
  –   secure quality
  –   write modular applications rather than
      “scripts”
Reusable

• “Standing on the Shoulders of
  Giants”
• “Zwerge auf den Schultern von
  Riesen”
• “nanos gigantium humeris
  insidentes”
Extensible
•What is the most popular about jQuery?
     - THE PLUGINS!

 $.fn.extend({
      accessibleTabs: function(config) {
         return this.each(function() {
             //...
         }
      }
 });


 $(".tabs").accessibleTabs();
Extensible
• Everything can have plugins!
• Tiny Form Validation script:
 addValidator : function(name,func){
   this.validators[name] = func;
 }

 this.addValidator('isText',function(el){
    var filter   = /^[a-zA-Z ]+$/;
    return filter.test(el.get('value'));
 });

 if( !this.validators['isText'](el) ){ //error!}
Extensible
•Extending something out there instead of
 writing it all over again
•Being prepared for demands that are not
 yet known
Optimized for Development

• Good Development Code != good
  Production Code
• Good for Development:
  – granular code split over many files
    • module / config / i18n / init / etc
  – many comments
  – examples
Optimized for Production

• Good Development Code != good
  Production Code
• Good for Production:
  – code combined into as few files as
    possible
  – comments and whitespace removed
  – optional code-minification
Optimized for Production

• YUI Compressor
  http://developer.yahoo.com/yui/
  compressor/
• Google Closure Compiler
  http://code.google.com/closure/
  compiler/
Optimized for Performance

• Caching of DOM-accesses
 var el = document.getElementById('bla');

• CSS is MUCH faster than JS when it’s
  about changing the DOM
 el.addClass('bla');

 instead of
 el.css({
    width:'20px',
    height:'20px',
    ...

 });
Optimized for Performance

• reduce “reflows”
  after every DOM-manipulation the
  Browser needs to rerender!
• Changing CSS is usually faster than
  changing the DOM

 $('<style type="text/css"> a { color: red; } </
 style>').appendTo('head');
Optimized for Performance

• changing the DOM using:
  – classic DOM Methods:
   el = document.getElementById('list');
   l1 = document.createElement('li');
   t1 = document.createTextNode('hello 1');
   l2 = document.createElement('li');
   t2 = document.createTextNode('hello 2');
   l3 = document.createElement('li');
   t3 = document.createTextNode('hello 3');
   l1.appendChild(t1);
   l2.appendChild(t2);
   l3.appendChild(t3);
   el.appendChild(t1).appendChild(t2).appendChild(t3);
Optimized for Performance

• changing the DOM using:
  – innerHTML:
   el = document.getElementById('list');
   li = '<li>hallo 1</li>';
   li += '<li>hallo 2</li>';
   li += '<li>hallo 3</li>';
   el.innerHTML = li;

  – faster than DOM-Methods (thanks to IE)
Optimized for Performance

• changing the DOM using:
  – innerHTML:
   el = document.getElementById('list');
   li = [];
   li.push('<li>hallo 1</li>');
   li.push('<li>hallo 2</li>');
   li.push('<li>hallo 3</li>');
   el.innerHTML = li.join('');

  – even faster because string
    concatenation in IE is slow
Optimized for Performance

• changing the DOM using:
  – innerHTML:
   el = document.getElementById('list');
   li = [];
   li[0] = '<li>hallo 1</li>';
   li[1] = '<li>hallo 2</li>';
   li[2] = '<li>hallo 3</li>';
   el.innerHTML = li.join('');

  – even faster as also array.push is slow
    in IE...
Optimized for Performance

• changing the DOM using:
  – DOM Fragment:
   l = document.getElementById('list');
   f = document.createDocumentFragment();
   l1 = document.createElement('li');
   t1 = document.createTextNode('hallo 1');
   ...
   l1.appendChild(t1);
   l2.appendChild(t2);
   l3.appendChild(t3);
   f.appendChild(l1).appendChild(l2).appendChild(l3);
   el.appendChild(f);

  – Even faster! Just 1 DOM access!
Secure

• XSS is a massive security issue
• never echo user inputs
• filter inputs!
  whitelisting not blacklisting
• define data types
• trust nothing and nobody
• be paranoid...
Secure

• Caja
  http://en.wikipedia.org/wiki/
  Caja_project
• “virtual iFrames”
• no direct access to native objects
• Transpiler on the Server
• YUI3 1st Javascript Library being
  compatible
International/Multilingual

• UTF-8
• RTL/Bidi
• If possible reuse strings that are in
  the HTML already
• Use standards
  – Text {0} more text {1} yet more text {2}
    Text {0:currency} more text {1:symbol} even
    more text {2:amount} // {variable:comment}
International/Multilingual

• Variable sentence structure requires
  multi step translation
  – T_WELCOME : {
       en_US:”We welcome {0:user}”
       de_DE:”Wir heissen {0:user} willkommen”
    }
  – getText(‘de_DE’,‘T_WELCOME’,{user:”Dude”})

• check ISO Standards
• HTML in Strings isn’t ideal but
  better than pseudo code
• bold = asian symbols unreadable
International/Multilingual
     TRANSLATIONS = { // check http://internationalisationtips.com

    O:    "{market} open",

    OT:   "{market} open in {timePeriod}",

    OE:   "{market} open early",

    OET: "{market} open early in {timePeriod}",

    OER: "{market} open early for {reason}",

    OERT: "{market} open early for {reason} in {timePeriod}",

    OL:   "{market} open late",

    OLT: "{market} open late in {timePeriod}",

    OLR: "{market} open late for {reason}",

    OLRT: "{market} open late for {reason} in {timePeriod}",

    C:    "{market} close",

    CT:   "{market} close in {timePeriod}",

    CE:   "{market} close early",

    CET: "{market} close early in {timePeriod}",

    CER: "{market} close early for {reason}",

    CERT: "{market} close early for {reason} in {timePeriod}",

    CL:   "{market} close late",

    CLT: "{market} close late in {timePeriod}",

    CLR: "{market} close late for {reason}",

    CLRT: "{market} close late for {reason} in {timePeriod}",

    X:    "{market} closed"
};
Optional

• Progressive Enhancement
  – Base functionality of the site needs to
    be available even though the user
    agent does not understand Javascript
  – Mobile != iPhone (Opera Mini is No.1!)
    • Search Machines
    • Paranoid Sysadmins
    • Y! has ~1% non-js Users -> Millions!
    • ...
Optional

• base page has interaction thanks to:
  – Links
  – Forms
  – (+ everything important is visible!)
• With Javascript:
  – Links that update the page become
    Buttons
  – Forms are being processed instantly
  – Infos can be hidden and shown
Accessible

• Tab order is super important
• using focus() we can direct the user
• tabindex=-1 makes everything
  focusable (for Javascript)
• Ajax works but mind the load time
• update Virtual Buffer
Accessible

• some Effects can make the JS
  Version more accessible
  – yellow fade to temporary highlight
    what changed
  – animated open close is easier to
    understand than a hard show/hide
Accessible

• WAI-ARIA
  – maps UI Elements that are well known
    on the Desktop to Elements in the
    Browser
  – teaches meaning to non-semantic
    markup
Accessible

• WAI-ARIA
  – proper realtime updates
    • Live Regions
  – real Form Validation state
    • aria-required="true"
    • aria-invalid="true"
  – real Dialogs
    • role="alert"
thank you :-)

• http://ginader.com
• http://twitter.com/ginader
• http://github.com/ginader/
• http://www.slideshare.net/ginader
• http://speakerrate.com/speakers/
  225-ginader

More Related Content

What's hot

iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless AppsRemy Sharp
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for MobileRemy Sharp
 
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesBeyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesCrashlytics
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricksambiescent
 
Drush - use full power - DrupalCamp Donetsk 2014
Drush - use full power - DrupalCamp Donetsk 2014Drush - use full power - DrupalCamp Donetsk 2014
Drush - use full power - DrupalCamp Donetsk 2014Alex S
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5osa_ora
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Alessandro Nadalin
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupalBlackCatWeb
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 

What's hot (20)

iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesBeyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
Drush - use full power - DrupalCamp Donetsk 2014
Drush - use full power - DrupalCamp Donetsk 2014Drush - use full power - DrupalCamp Donetsk 2014
Drush - use full power - DrupalCamp Donetsk 2014
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
Drupal, meet Assetic
Drupal, meet AsseticDrupal, meet Assetic
Drupal, meet Assetic
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
 
YQL & Yahoo! Apis
YQL & Yahoo! ApisYQL & Yahoo! Apis
YQL & Yahoo! Apis
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 

Viewers also liked

Joining Accessibility and UX for Accessible UX
Joining Accessibility and UX for Accessible UXJoining Accessibility and UX for Accessible UX
Joining Accessibility and UX for Accessible UXDavid Sloan
 
Again with the Ajax accessibility
Again with the Ajax accessibilityAgain with the Ajax accessibility
Again with the Ajax accessibilityChristian Heilmann
 
HTML5 & WAI-ARIA - Happy Families
HTML5 & WAI-ARIA - Happy FamiliesHTML5 & WAI-ARIA - Happy Families
HTML5 & WAI-ARIA - Happy FamiliesSteven Faulkner
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oiljameswillweb
 
Teach your Browser new tricks
Teach your Browser new tricksTeach your Browser new tricks
Teach your Browser new tricksDirk Ginader
 
Responsive Design Overview for UB CIT
Responsive Design Overview for UB CITResponsive Design Overview for UB CIT
Responsive Design Overview for UB CITAdrian Roselli
 
Keyboard and Interaction Accessibility Techniques
Keyboard and Interaction Accessibility TechniquesKeyboard and Interaction Accessibility Techniques
Keyboard and Interaction Accessibility TechniquesJared Smith
 
CSS pattern libraries
CSS pattern librariesCSS pattern libraries
CSS pattern librariesRuss Weakley
 

Viewers also liked (8)

Joining Accessibility and UX for Accessible UX
Joining Accessibility and UX for Accessible UXJoining Accessibility and UX for Accessible UX
Joining Accessibility and UX for Accessible UX
 
Again with the Ajax accessibility
Again with the Ajax accessibilityAgain with the Ajax accessibility
Again with the Ajax accessibility
 
HTML5 & WAI-ARIA - Happy Families
HTML5 & WAI-ARIA - Happy FamiliesHTML5 & WAI-ARIA - Happy Families
HTML5 & WAI-ARIA - Happy Families
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
 
Teach your Browser new tricks
Teach your Browser new tricksTeach your Browser new tricks
Teach your Browser new tricks
 
Responsive Design Overview for UB CIT
Responsive Design Overview for UB CITResponsive Design Overview for UB CIT
Responsive Design Overview for UB CIT
 
Keyboard and Interaction Accessibility Techniques
Keyboard and Interaction Accessibility TechniquesKeyboard and Interaction Accessibility Techniques
Keyboard and Interaction Accessibility Techniques
 
CSS pattern libraries
CSS pattern librariesCSS pattern libraries
CSS pattern libraries
 

Similar to Javascript done right - Open Web Camp III

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and DesktopElizabeth Smith
 
Leveling Up at JavaScript
Leveling Up at JavaScriptLeveling Up at JavaScript
Leveling Up at JavaScriptRaymond Camden
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaolaAppsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaoladrewz lin
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointBob German
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World DominationcPanel
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
How ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps lifeHow ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps life琛琳 饶
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanshipbokonen
 

Similar to Javascript done right - Open Web Camp III (20)

Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Return of c++
Return of c++Return of c++
Return of c++
 
Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
Leveling Up at JavaScript
Leveling Up at JavaScriptLeveling Up at JavaScript
Leveling Up at JavaScript
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaolaAppsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaola
 
Performance patterns
Performance patternsPerformance patterns
Performance patterns
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePoint
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
How ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps lifeHow ElasticSearch lives in my DevOps life
How ElasticSearch lives in my DevOps life
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 

More from Dirk Ginader

HTML5 Dev Conf - Sass, Compass & the new Webdev tools
HTML5 Dev Conf - Sass, Compass &  the new Webdev toolsHTML5 Dev Conf - Sass, Compass &  the new Webdev tools
HTML5 Dev Conf - Sass, Compass & the new Webdev toolsDirk Ginader
 
Sass, Compass and the new tools - Open Web Camp IV
Sass, Compass and the new tools - Open Web Camp IVSass, Compass and the new tools - Open Web Camp IV
Sass, Compass and the new tools - Open Web Camp IVDirk Ginader
 
The accessibility features of Yahoo! Finance
The accessibility features of Yahoo! FinanceThe accessibility features of Yahoo! Finance
The accessibility features of Yahoo! FinanceDirk Ginader
 
Javascript done right
Javascript done rightJavascript done right
Javascript done rightDirk Ginader
 
Javascript auf Client und Server mit node.js - webtech 2010
Javascript auf Client und Server mit node.js - webtech 2010Javascript auf Client und Server mit node.js - webtech 2010
Javascript auf Client und Server mit node.js - webtech 2010Dirk Ginader
 
the 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIthe 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIDirk Ginader
 
Das Web Als Datenbank Mit Yql Und Pipes
Das Web Als Datenbank Mit Yql Und PipesDas Web Als Datenbank Mit Yql Und Pipes
Das Web Als Datenbank Mit Yql Und PipesDirk Ginader
 
Die 5 Ebenen Barriererfreier Web Entwicklung
Die 5 Ebenen Barriererfreier Web EntwicklungDie 5 Ebenen Barriererfreier Web Entwicklung
Die 5 Ebenen Barriererfreier Web EntwicklungDirk Ginader
 
The 5 Layers of Web Accessibility
The 5 Layers of Web AccessibilityThe 5 Layers of Web Accessibility
The 5 Layers of Web AccessibilityDirk Ginader
 
Accessible Javascript with and without WAI ARIA
Accessible Javascript with and without WAI ARIAAccessible Javascript with and without WAI ARIA
Accessible Javascript with and without WAI ARIADirk Ginader
 
Avoiding common Accessibility mistakes
Avoiding common Accessibility mistakesAvoiding common Accessibility mistakes
Avoiding common Accessibility mistakesDirk Ginader
 
Accessible Javascript using Frameworks - Barcamp London 5
Accessible Javascript using Frameworks - Barcamp London 5Accessible Javascript using Frameworks - Barcamp London 5
Accessible Javascript using Frameworks - Barcamp London 5Dirk Ginader
 
Accessible Javascript mit Frameworks - Best of Accessibility 2008
Accessible Javascript mit Frameworks - Best of Accessibility 2008Accessible Javascript mit Frameworks - Best of Accessibility 2008
Accessible Javascript mit Frameworks - Best of Accessibility 2008Dirk Ginader
 
Accessible Javascript - Barcamp Brighton 2
Accessible Javascript - Barcamp Brighton 2Accessible Javascript - Barcamp Brighton 2
Accessible Javascript - Barcamp Brighton 2Dirk Ginader
 

More from Dirk Ginader (14)

HTML5 Dev Conf - Sass, Compass & the new Webdev tools
HTML5 Dev Conf - Sass, Compass &  the new Webdev toolsHTML5 Dev Conf - Sass, Compass &  the new Webdev tools
HTML5 Dev Conf - Sass, Compass & the new Webdev tools
 
Sass, Compass and the new tools - Open Web Camp IV
Sass, Compass and the new tools - Open Web Camp IVSass, Compass and the new tools - Open Web Camp IV
Sass, Compass and the new tools - Open Web Camp IV
 
The accessibility features of Yahoo! Finance
The accessibility features of Yahoo! FinanceThe accessibility features of Yahoo! Finance
The accessibility features of Yahoo! Finance
 
Javascript done right
Javascript done rightJavascript done right
Javascript done right
 
Javascript auf Client und Server mit node.js - webtech 2010
Javascript auf Client und Server mit node.js - webtech 2010Javascript auf Client und Server mit node.js - webtech 2010
Javascript auf Client und Server mit node.js - webtech 2010
 
the 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIthe 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp II
 
Das Web Als Datenbank Mit Yql Und Pipes
Das Web Als Datenbank Mit Yql Und PipesDas Web Als Datenbank Mit Yql Und Pipes
Das Web Als Datenbank Mit Yql Und Pipes
 
Die 5 Ebenen Barriererfreier Web Entwicklung
Die 5 Ebenen Barriererfreier Web EntwicklungDie 5 Ebenen Barriererfreier Web Entwicklung
Die 5 Ebenen Barriererfreier Web Entwicklung
 
The 5 Layers of Web Accessibility
The 5 Layers of Web AccessibilityThe 5 Layers of Web Accessibility
The 5 Layers of Web Accessibility
 
Accessible Javascript with and without WAI ARIA
Accessible Javascript with and without WAI ARIAAccessible Javascript with and without WAI ARIA
Accessible Javascript with and without WAI ARIA
 
Avoiding common Accessibility mistakes
Avoiding common Accessibility mistakesAvoiding common Accessibility mistakes
Avoiding common Accessibility mistakes
 
Accessible Javascript using Frameworks - Barcamp London 5
Accessible Javascript using Frameworks - Barcamp London 5Accessible Javascript using Frameworks - Barcamp London 5
Accessible Javascript using Frameworks - Barcamp London 5
 
Accessible Javascript mit Frameworks - Best of Accessibility 2008
Accessible Javascript mit Frameworks - Best of Accessibility 2008Accessible Javascript mit Frameworks - Best of Accessibility 2008
Accessible Javascript mit Frameworks - Best of Accessibility 2008
 
Accessible Javascript - Barcamp Brighton 2
Accessible Javascript - Barcamp Brighton 2Accessible Javascript - Barcamp Brighton 2
Accessible Javascript - Barcamp Brighton 2
 

Recently uploaded

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)wesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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 WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

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)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Javascript done right - Open Web Camp III

  • 1. Dirk Ginader | Yahoo! Inc. Javascript done right @ginader
  • 2. What is “good” Javascript? • From a User Perspective?
  • 3. What is “good” Javascript? • From a User Perspective: – THEY DON’T CARE!* *as long as it works...
  • 4. What is “good” Javascript? • From a Developer Perspective?
  • 5. What is “good” Javascript? • From a Developer Perspective: – understandable – reusable – extensible – optimized – secure – internationalized – optional – accessible
  • 6. Understandable • don’t be “too clever”
  • 7. Understandable • don’t be “too clever”
  • 8. Understandable • not everybody understands: – Ternary: • var d = (x < m) ? 'l' : 'r';
  • 9. Understandable • not everybody understands: – Regex: • ^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+-+)|([A-Za- z0-9]+.+)|([A-Za-z0-9]+++))*[A-Za- z0-9]+@((w+-+)|(w+.))*w{1,63}.[a-zA-Z] {2,6}$
  • 10. Understandable • not everybody understands: – Shakespeare: • /(bb|[^b]{2})/
  • 11. Understandable • If there’s no good way around cleverness then: – good naming – documentation
  • 12. for more WTF check • http://wtfjs.com
  • 13. Understandable -> Documented • Writing Docs isn’t fun • Reading Code you wrote 5 years ago and didn’t document is worse... • Reading undocumented code someone else wrote even more so...
  • 14. Understandable -> Documented • use clear variable and function names: – a = b(c) // Whut? – user = getUserOfProduct(productId) // Alright! • good comments – // IE seems to break here... – // dirty hack. This must never go live! – // this works. No idea why. Better don’t touch.
  • 15. Understandable -> Documented • exceptionally good comments: – YUI Doc: http://developer.yahoo.com/ yui/yuidoc/ – creates the YUI API Dos automatically – simple Javadoc syntax /** * short description * @method methodName * @param {bool} * @returm {type} */
  • 16. Understandable -> Documented • YUI Doc now even prettier thanks to Carlo & Dana: http://www.yuiblog.com/blog/ 2010/10/01/yuidoc-dana-theme/
  • 17. Understandable -> Structured • HTML – Markup • CSS – Design • Javascript – Interaction
  • 18. Understandable -> Structured • CSS for Javascript – <script> document.documentElement.className += ' js'; </script> <style> .module{ /* with JS */ } .js .module{ /* without JS */ } </style>
  • 19. Understandable -> Structured • HTML for Javascript – Mustache Templating Partials for Ajax content – /partials/login_success.html – Hello {{user_name}} You have sucesfully registered Your currently have {{user_points}} points – { user_name : “dude”, user_points : 123 } – http://mustache.github.com/
  • 20. Reusable • find patterns • largest common denominator • when you’re writing a new dropdown menu every month something is very wrong... • write ONE dropdown menu and keep making it better
  • 21. Reusable • open source != “I’m giving it away for free” • open source == “I get free testers, co-developers, fame and fortune” • github is full of excellent code • “FORK OFF” - make it better! • a plugin for an existing library is a great start
  • 22. Reusable • How do you write Javascript? – jQuery, YUI and alike? – all “pure”?
  • 23. Reusable • You’re using and understand just one Javascript Framework? – learn Javascript! – look under the hood – understand Errors
  • 24. Reusable • You don’t use Frameworks? – you should!
  • 25. Reusable • Javascript Frameworks/Libraries help to – not reinvent the wheel all over again – keep Code fresh – secure quality – write modular applications rather than “scripts”
  • 26. Reusable • “Standing on the Shoulders of Giants” • “Zwerge auf den Schultern von Riesen” • “nanos gigantium humeris insidentes”
  • 27. Extensible •What is the most popular about jQuery? - THE PLUGINS! $.fn.extend({ accessibleTabs: function(config) { return this.each(function() { //... } } }); $(".tabs").accessibleTabs();
  • 28. Extensible • Everything can have plugins! • Tiny Form Validation script: addValidator : function(name,func){ this.validators[name] = func; } this.addValidator('isText',function(el){ var filter = /^[a-zA-Z ]+$/; return filter.test(el.get('value')); }); if( !this.validators['isText'](el) ){ //error!}
  • 29. Extensible •Extending something out there instead of writing it all over again •Being prepared for demands that are not yet known
  • 30. Optimized for Development • Good Development Code != good Production Code • Good for Development: – granular code split over many files • module / config / i18n / init / etc – many comments – examples
  • 31. Optimized for Production • Good Development Code != good Production Code • Good for Production: – code combined into as few files as possible – comments and whitespace removed – optional code-minification
  • 32. Optimized for Production • YUI Compressor http://developer.yahoo.com/yui/ compressor/ • Google Closure Compiler http://code.google.com/closure/ compiler/
  • 33. Optimized for Performance • Caching of DOM-accesses var el = document.getElementById('bla'); • CSS is MUCH faster than JS when it’s about changing the DOM el.addClass('bla'); instead of el.css({ width:'20px', height:'20px', ... });
  • 34. Optimized for Performance • reduce “reflows” after every DOM-manipulation the Browser needs to rerender! • Changing CSS is usually faster than changing the DOM $('<style type="text/css"> a { color: red; } </ style>').appendTo('head');
  • 35. Optimized for Performance • changing the DOM using: – classic DOM Methods: el = document.getElementById('list'); l1 = document.createElement('li'); t1 = document.createTextNode('hello 1'); l2 = document.createElement('li'); t2 = document.createTextNode('hello 2'); l3 = document.createElement('li'); t3 = document.createTextNode('hello 3'); l1.appendChild(t1); l2.appendChild(t2); l3.appendChild(t3); el.appendChild(t1).appendChild(t2).appendChild(t3);
  • 36. Optimized for Performance • changing the DOM using: – innerHTML: el = document.getElementById('list'); li = '<li>hallo 1</li>'; li += '<li>hallo 2</li>'; li += '<li>hallo 3</li>'; el.innerHTML = li; – faster than DOM-Methods (thanks to IE)
  • 37. Optimized for Performance • changing the DOM using: – innerHTML: el = document.getElementById('list'); li = []; li.push('<li>hallo 1</li>'); li.push('<li>hallo 2</li>'); li.push('<li>hallo 3</li>'); el.innerHTML = li.join(''); – even faster because string concatenation in IE is slow
  • 38. Optimized for Performance • changing the DOM using: – innerHTML: el = document.getElementById('list'); li = []; li[0] = '<li>hallo 1</li>'; li[1] = '<li>hallo 2</li>'; li[2] = '<li>hallo 3</li>'; el.innerHTML = li.join(''); – even faster as also array.push is slow in IE...
  • 39. Optimized for Performance • changing the DOM using: – DOM Fragment: l = document.getElementById('list'); f = document.createDocumentFragment(); l1 = document.createElement('li'); t1 = document.createTextNode('hallo 1'); ... l1.appendChild(t1); l2.appendChild(t2); l3.appendChild(t3); f.appendChild(l1).appendChild(l2).appendChild(l3); el.appendChild(f); – Even faster! Just 1 DOM access!
  • 40. Secure • XSS is a massive security issue • never echo user inputs • filter inputs! whitelisting not blacklisting • define data types • trust nothing and nobody • be paranoid...
  • 41. Secure • Caja http://en.wikipedia.org/wiki/ Caja_project • “virtual iFrames” • no direct access to native objects • Transpiler on the Server • YUI3 1st Javascript Library being compatible
  • 42. International/Multilingual • UTF-8 • RTL/Bidi • If possible reuse strings that are in the HTML already • Use standards – Text {0} more text {1} yet more text {2} Text {0:currency} more text {1:symbol} even more text {2:amount} // {variable:comment}
  • 43. International/Multilingual • Variable sentence structure requires multi step translation – T_WELCOME : { en_US:”We welcome {0:user}” de_DE:”Wir heissen {0:user} willkommen” } – getText(‘de_DE’,‘T_WELCOME’,{user:”Dude”}) • check ISO Standards • HTML in Strings isn’t ideal but better than pseudo code • bold = asian symbols unreadable
  • 44. International/Multilingual TRANSLATIONS = { // check http://internationalisationtips.com O: "{market} open", OT: "{market} open in {timePeriod}", OE: "{market} open early", OET: "{market} open early in {timePeriod}", OER: "{market} open early for {reason}", OERT: "{market} open early for {reason} in {timePeriod}", OL: "{market} open late", OLT: "{market} open late in {timePeriod}", OLR: "{market} open late for {reason}", OLRT: "{market} open late for {reason} in {timePeriod}", C: "{market} close", CT: "{market} close in {timePeriod}", CE: "{market} close early", CET: "{market} close early in {timePeriod}", CER: "{market} close early for {reason}", CERT: "{market} close early for {reason} in {timePeriod}", CL: "{market} close late", CLT: "{market} close late in {timePeriod}", CLR: "{market} close late for {reason}", CLRT: "{market} close late for {reason} in {timePeriod}", X: "{market} closed" };
  • 45. Optional • Progressive Enhancement – Base functionality of the site needs to be available even though the user agent does not understand Javascript – Mobile != iPhone (Opera Mini is No.1!) • Search Machines • Paranoid Sysadmins • Y! has ~1% non-js Users -> Millions! • ...
  • 46. Optional • base page has interaction thanks to: – Links – Forms – (+ everything important is visible!) • With Javascript: – Links that update the page become Buttons – Forms are being processed instantly – Infos can be hidden and shown
  • 47. Accessible • Tab order is super important • using focus() we can direct the user • tabindex=-1 makes everything focusable (for Javascript) • Ajax works but mind the load time • update Virtual Buffer
  • 48. Accessible • some Effects can make the JS Version more accessible – yellow fade to temporary highlight what changed – animated open close is easier to understand than a hard show/hide
  • 49. Accessible • WAI-ARIA – maps UI Elements that are well known on the Desktop to Elements in the Browser – teaches meaning to non-semantic markup
  • 50. Accessible • WAI-ARIA – proper realtime updates • Live Regions – real Form Validation state • aria-required="true" • aria-invalid="true" – real Dialogs • role="alert"
  • 51.
  • 52. thank you :-) • http://ginader.com • http://twitter.com/ginader • http://github.com/ginader/ • http://www.slideshare.net/ginader • http://speakerrate.com/speakers/ 225-ginader

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n