SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
Progressive
 Enhancement
With JavaScript
       and Ajax




                  Highland Fling 2007
                  Christian Heilmann
• As web developers we are in a
  very lucky position.
• Unlike real world products,
  web sites do not have a fixed
  state.
• Web documents were right
  from the start meant to be
  adaptive to their environment.
• By keeping things flexible and
  adaptive we can please all
  consumers.

                                   http://www.flickr.com/photos/oskay/420878465/
• Real life enhancement
• Real life has some ideas of
  progressive enhancement,
  most of which are old
  chestnuts:
  – Measure twice, cut once.
  – Check the depth of the lake
    before you plunge in.
  – Try before you buy
  – = Use Bittorrent
• The same logic applies to
  JavaScript and Ajax:
  – Test if JavaScript is available.
  – Test if the DOM is supported
  – Test for the HTML you want to
    use.
  – Test for any object you want to
    use.
  – Don’t rely on the connection to
    be available.
• Testing for JavaScript is easy,
  simply don’t make your
  product rely on JavaScript:
     – Death to href=“javascript:foo()”
     – Death to onclick=“foo()”
     – Who the hell ever told you to
       use onclick=“javascript:foo()” ?

• Don’t mix HTML and
  JavaScript, use the DOM to
  access HTML.
• The DOM is your API to the
  document.
http://www.flickr.com/photos/jungle_boy/140233674/
• Testing for DOM support is as easy:
  – Check that getElementById and is available.
  – If you still care about Opera 6 also test for createTextNode




     function init(){
       if( document.getElementById &&
           document.createTextNode )
         // we have DOM, wahey!
         checkDependencies();
       }
     }
• Testing for the HTML you need is also easy:
  – Check that all the elements are available.




    function checkDependencies(){
       var usedIds = ['nav','content'];
       var isOk = true;
       for(var i = 0; usedIds[i]!==undefined; i++) {
         if( !document.getElementById( usedIds[i] ) ){
           isOk = false;
         }
       }
       return isOk;
     }
• Testing for the HTML you need is also easy:
  – Check that all the elements are available.
  – Check that they also have the right child nodes




     function myNavStuff(){
        var n = document.getElementById('nav');
        if(n.getElementsByTagName('ul').length > 0){
          // I got your code right here!
        }
      }
• Testing for object availability
   – Simply test for any object before you access it




     var request;
     try{
       request = new XMLHttpRequest();
     }catch(error){
       try{
         request = new ActiveXObject(quot;Microsoft.XMLHTTPquot;);
       }catch(error){
         return true;
       }
     }
• Prepare for unreliable and
  flaky connections.
  – Set a timer to time out and
    abort the connection after a
    certain period has passed.
  – Define a success and failure
    case for any connection.
  – Make sure you avoid caching
    issues by setting an expired
    HTTP header on your Ajax calls
• This is the “how” of
  progressive enhancement
  with JavaScript and Ajax.
• The question however is why
  use JavaScript at all?
• After all it can be turned off.
• Instead we can use the
  amazing new trick called
  “CSS only solutions”.
• Why bother with writing
  complex scripts when you can
  do the same with some easy
  lines of CSS?
• Showing and hiding menus?
  #nav li ul { display:none }
  #nav li:hover ul {
      display:block
  }
• Using CSS for behaviour is
  based on one trick, which is
  pseudo selectors like :hover,
  :active and :focus
• These have several problems:
  – Some browsers only support
    them on interactive elements
    like links and buttons.
  – They have a strict on or off
    state.
  – and they fail for a certain user
    group…
• Keyboard access support in
  HTML and browsers is bad.
• Support for :active and :focus
  is even worse.
• Which means that CSS only
  solutions with keyboard
  support turn out to be HTML
  soup nightmares (nesting
  tables inside links…)
• In essence, CSS only solutions
  are a bit of a shifty character
  and you don’t know if you can
  trust them.
• It is also debateable if CSS
  only solutions are in the end
  easier than JS solutions.
• JavaScript has so many more
  options for you:
  – Real testing for support of
    objects
  – Real event handling including
    simulation of application
    keyboard handling (cursors
    instead of tabbing)
  – timeout() to allow for user errors
  – Creation of necessary markup
    on demand.
• JavaScript has so many more
  options for you:
    – Test of available screen estate
    – Loading of extra content on
      demand




 http://www.flickr.com/photos/drewm/227562632/
• Does this mean that only
  scripters should create
  interfaces and CSS is not
  needed?
• Not at all, as first of all CSS
  can help JavaScript a lot.




http://www.flickr.com/photos/drewm/225911999/in/set-507727/
• Task: Hide all list items in the first UL
   – A lot of code, that one…




 window.onload = function(){
   if(document.getElementById && document.createTextNode){
     var uls = document.getElementsByTagName('ul');
     if(uls.length > 0){
       var lis = uls[0].getElementsByTagName('li');
       for(var i = 0, j = lis.length; i < j; i++){
         lis[i].style.display = 'none';
       }
     }
   }
 }
• Task: Hide all list items in the first UL
   – How about leaving the main job to the CSS parser?




window.onload = function(){
  if(document.getElementById && document.createTextNode){
    var b = document.body;
    b.className += b.className ? ' dynamic' : 'dynamic';
  }
}
<style type=quot;text/cssquot;>
  body.dynamic ul li{
    display:none;
  }
</style>
• This also allows you to keep
  the whole look and feel of
  your scripts in the hands of
  the CSS maintainers.
• All you need to do is make
  sure you communicate the
  class and ID names with
  them.
• You achieve highest flexibility
  by separating those and the
  text labels out into own
  includes:
   slideshow.js
   slideshow-css.js
   slideshow-labels.js

      slideshow.css = {

      'navigationID':'nav',
        'contentID':'main',
        'hide class':'hide'
      }
• There is a danger in
  progressive enhancement
  with JavaScript though:
• Be aware that what you
  enhance is as important as
  how you enhance it.
• A solution that doesn’t really
  make sense shouldn’t be
  enhanced, but changed.
• Useless progressive
  enhancement.




    Pointless name dropping

      Get on with it…
• It is important to know your
  audience
• It is important to keep up with
  technology as a lot of truths
  of the past are not applicable
  any longer.
• Research what can be
  enhanced and how.
• Example “connected select
  boxes”:
• Research what can be
  enhanced and how.
• Example “hcard to
  Googlemap”
• So why isn’t progressive
  enhancement yet a common
  practice?




http://www.flickr.com/photos/urlgirl/199044322/
• Stockholm Syndrome
• Stockholm Syndrome
• Enhanced interfaces don’t go
  down too well with the
  mainstream audience, we are
  used to waiting and things
  breaking.
• Technologies are perceived as
  given, no need to improve
  them.
• Monetary reasons
• Progressive Enhancement
  costs money
• As with any best practice
  there is no immediate
  tangible benefit
• Show desire
• You can help to change this
• Look at things, and see how
  you can improve them
• If need be, do it on the sly
  (hcard in Yahoo! Local)
• Benefit from experience of
  others
• A lot of tricks that helped us
  in the past can be brushed up
  and renewed now.
• Example “lowsrc”
• Keep your feelers out there.
• Read up on technologies and
  what is done with them.
• Hot:
  – http://www.w3.org/TR/aria-
    roadmap/
  – http://www.whatwg.org/
• Contact, subscribe, talk,
  share.
• If you know something, please
  tell others:
  http://makemeaspeaker.com
• Good progressive
  enhancement helps the user,
  and not the developer.
     – Automatic saving of drafts in
       email apps
     – Parallel upload of content while
       you can add meta data
     – Making it easy and fun to add
       content.
     – Preventing unnecessary steps.




http://www.flickr.com/photos/radiofree/286343390/
THANKS!




chris.heilmann@gmail.com
http://wait-till-i.com
http://icant.co.uk
Flickr/delicious: codepo8

Contenu connexe

Tendances

Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOMDaiwei Lu
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM ManipulationsYnon Perek
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009Ralph Whitbeck
 
Taiwan Web Standards Talk 2011
Taiwan Web Standards Talk 2011Taiwan Web Standards Talk 2011
Taiwan Web Standards Talk 2011Zi Bin Cheah
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterpriseDave Artz
 
10 java script projects full source code
10 java script projects full source code10 java script projects full source code
10 java script projects full source codeLaurence Svekis ✔
 
Google’s PRPL Web development pattern
Google’s PRPL Web development patternGoogle’s PRPL Web development pattern
Google’s PRPL Web development patternJeongkyu Shin
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)jeresig
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web ComponentsAndrew Rota
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingYorick Phoenix
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_queryFajar Baskoro
 
When dynamic becomes static - the next step in web caching techniques
When dynamic becomes static - the next step in web caching techniquesWhen dynamic becomes static - the next step in web caching techniques
When dynamic becomes static - the next step in web caching techniquesWim Godden
 
jQuery and the W3C
jQuery and the W3CjQuery and the W3C
jQuery and the W3Cjeresig
 

Tendances (20)

Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Taiwan Web Standards Talk 2011
Taiwan Web Standards Talk 2011Taiwan Web Standards Talk 2011
Taiwan Web Standards Talk 2011
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
10 java script projects full source code
10 java script projects full source code10 java script projects full source code
10 java script projects full source code
 
Google’s PRPL Web development pattern
Google’s PRPL Web development patternGoogle’s PRPL Web development pattern
Google’s PRPL Web development pattern
 
Backbone
BackboneBackbone
Backbone
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event Handling
 
Vue.js for beginners
Vue.js for beginnersVue.js for beginners
Vue.js for beginners
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
 
When dynamic becomes static - the next step in web caching techniques
When dynamic becomes static - the next step in web caching techniquesWhen dynamic becomes static - the next step in web caching techniques
When dynamic becomes static - the next step in web caching techniques
 
jQuery and the W3C
jQuery and the W3CjQuery and the W3C
jQuery and the W3C
 

Similaire à Progressive Enhancement with JavaScript and Ajax

Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Libraryjeresig
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSNaga Harish M
 
The road to professional web development
The road to professional web developmentThe road to professional web development
The road to professional web developmentChristian Heilmann
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
 
Automated Frontend Testing
Automated Frontend TestingAutomated Frontend Testing
Automated Frontend TestingNeil Crosby
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MITjeresig
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQueryDanWooster1
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
How I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScriptHow I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScriptKevin Read
 
Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8Kevin Read
 
Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyondmguillem
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4alexsaves
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScalePatrick Chanezon
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWebDave Bouwman
 
jQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsEugene Andruszczenko
 

Similaire à Progressive Enhancement with JavaScript and Ajax (20)

Seven Reasons for Code Bloat
Seven Reasons for Code BloatSeven Reasons for Code Bloat
Seven Reasons for Code Bloat
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
The road to professional web development
The road to professional web developmentThe road to professional web development
The road to professional web development
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Automated Frontend Testing
Automated Frontend TestingAutomated Frontend Testing
Automated Frontend Testing
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MIT
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQuery
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
How I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScriptHow I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScript
 
Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8
 
Shifting Gears
Shifting GearsShifting Gears
Shifting Gears
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
 
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and ScaleGDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWeb
 
jQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh Events
 

Plus de Christian Heilmann

Develop, Debug, Learn? - Dotjs2019
Develop, Debug, Learn? - Dotjs2019Develop, Debug, Learn? - Dotjs2019
Develop, Debug, Learn? - Dotjs2019Christian Heilmann
 
Taking the "vile" out of privilege
Taking the "vile" out of privilegeTaking the "vile" out of privilege
Taking the "vile" out of privilegeChristian Heilmann
 
Seven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloChristian Heilmann
 
Artificial intelligence for humans… #AIDC2018 keynote
Artificial intelligence for humans… #AIDC2018 keynoteArtificial intelligence for humans… #AIDC2018 keynote
Artificial intelligence for humans… #AIDC2018 keynoteChristian Heilmann
 
Killing the golden calf of coding - We are Developers keynote
Killing the golden calf of coding - We are Developers keynoteKilling the golden calf of coding - We are Developers keynote
Killing the golden calf of coding - We are Developers keynoteChristian Heilmann
 
Progressive Web Apps - Techdays Finland
Progressive Web Apps - Techdays FinlandProgressive Web Apps - Techdays Finland
Progressive Web Apps - Techdays FinlandChristian Heilmann
 
Taking the "vile" out of privilege
Taking the "vile" out of privilegeTaking the "vile" out of privilege
Taking the "vile" out of privilegeChristian Heilmann
 
Five ways to be a happier JavaScript developer
Five ways to be a happier JavaScript developerFive ways to be a happier JavaScript developer
Five ways to be a happier JavaScript developerChristian Heilmann
 
Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"Christian Heilmann
 
You learned JavaScript - now what?
You learned JavaScript - now what?You learned JavaScript - now what?
You learned JavaScript - now what?Christian Heilmann
 
Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"Christian Heilmann
 
Progressive Web Apps - Covering the best of both worlds - DevReach
Progressive Web Apps - Covering the best of both worlds - DevReachProgressive Web Apps - Covering the best of both worlds - DevReach
Progressive Web Apps - Covering the best of both worlds - DevReachChristian Heilmann
 
Progressive Web Apps - Covering the best of both worlds
Progressive Web Apps - Covering the best of both worldsProgressive Web Apps - Covering the best of both worlds
Progressive Web Apps - Covering the best of both worldsChristian Heilmann
 
Non-trivial pursuits: Learning machines and forgetful humans
Non-trivial pursuits: Learning machines and forgetful humansNon-trivial pursuits: Learning machines and forgetful humans
Non-trivial pursuits: Learning machines and forgetful humansChristian Heilmann
 
Progressive Web Apps - Bringing the web front and center
Progressive Web Apps - Bringing the web front and center Progressive Web Apps - Bringing the web front and center
Progressive Web Apps - Bringing the web front and center Christian Heilmann
 
CSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlCSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlChristian Heilmann
 
Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017Christian Heilmann
 
The Soul in The Machine - Developing for Humans (FrankenJS edition)
The Soul in The Machine - Developing for Humans (FrankenJS edition)The Soul in The Machine - Developing for Humans (FrankenJS edition)
The Soul in The Machine - Developing for Humans (FrankenJS edition)Christian Heilmann
 

Plus de Christian Heilmann (20)

Develop, Debug, Learn? - Dotjs2019
Develop, Debug, Learn? - Dotjs2019Develop, Debug, Learn? - Dotjs2019
Develop, Debug, Learn? - Dotjs2019
 
Hinting at a better web
Hinting at a better webHinting at a better web
Hinting at a better web
 
Taking the "vile" out of privilege
Taking the "vile" out of privilegeTaking the "vile" out of privilege
Taking the "vile" out of privilege
 
Seven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC Oslo
 
Artificial intelligence for humans… #AIDC2018 keynote
Artificial intelligence for humans… #AIDC2018 keynoteArtificial intelligence for humans… #AIDC2018 keynote
Artificial intelligence for humans… #AIDC2018 keynote
 
Killing the golden calf of coding - We are Developers keynote
Killing the golden calf of coding - We are Developers keynoteKilling the golden calf of coding - We are Developers keynote
Killing the golden calf of coding - We are Developers keynote
 
Progressive Web Apps - Techdays Finland
Progressive Web Apps - Techdays FinlandProgressive Web Apps - Techdays Finland
Progressive Web Apps - Techdays Finland
 
Taking the "vile" out of privilege
Taking the "vile" out of privilegeTaking the "vile" out of privilege
Taking the "vile" out of privilege
 
Five ways to be a happier JavaScript developer
Five ways to be a happier JavaScript developerFive ways to be a happier JavaScript developer
Five ways to be a happier JavaScript developer
 
Taking the P out of PWA
Taking the P out of PWATaking the P out of PWA
Taking the P out of PWA
 
Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"
 
You learned JavaScript - now what?
You learned JavaScript - now what?You learned JavaScript - now what?
You learned JavaScript - now what?
 
Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"Sacrificing the golden calf of "coding"
Sacrificing the golden calf of "coding"
 
Progressive Web Apps - Covering the best of both worlds - DevReach
Progressive Web Apps - Covering the best of both worlds - DevReachProgressive Web Apps - Covering the best of both worlds - DevReach
Progressive Web Apps - Covering the best of both worlds - DevReach
 
Progressive Web Apps - Covering the best of both worlds
Progressive Web Apps - Covering the best of both worldsProgressive Web Apps - Covering the best of both worlds
Progressive Web Apps - Covering the best of both worlds
 
Non-trivial pursuits: Learning machines and forgetful humans
Non-trivial pursuits: Learning machines and forgetful humansNon-trivial pursuits: Learning machines and forgetful humans
Non-trivial pursuits: Learning machines and forgetful humans
 
Progressive Web Apps - Bringing the web front and center
Progressive Web Apps - Bringing the web front and center Progressive Web Apps - Bringing the web front and center
Progressive Web Apps - Bringing the web front and center
 
CSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlCSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. Control
 
Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017Leveling up your JavaScipt - DrupalJam 2017
Leveling up your JavaScipt - DrupalJam 2017
 
The Soul in The Machine - Developing for Humans (FrankenJS edition)
The Soul in The Machine - Developing for Humans (FrankenJS edition)The Soul in The Machine - Developing for Humans (FrankenJS edition)
The Soul in The Machine - Developing for Humans (FrankenJS edition)
 

Dernier

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
🐬 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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
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
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Dernier (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced 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 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
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
 
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)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Progressive Enhancement with JavaScript and Ajax

  • 1. Progressive Enhancement With JavaScript and Ajax Highland Fling 2007 Christian Heilmann
  • 2. • As web developers we are in a very lucky position. • Unlike real world products, web sites do not have a fixed state. • Web documents were right from the start meant to be adaptive to their environment. • By keeping things flexible and adaptive we can please all consumers. http://www.flickr.com/photos/oskay/420878465/
  • 3. • Real life enhancement
  • 4. • Real life has some ideas of progressive enhancement, most of which are old chestnuts: – Measure twice, cut once. – Check the depth of the lake before you plunge in. – Try before you buy – = Use Bittorrent
  • 5. • The same logic applies to JavaScript and Ajax: – Test if JavaScript is available. – Test if the DOM is supported – Test for the HTML you want to use. – Test for any object you want to use. – Don’t rely on the connection to be available.
  • 6. • Testing for JavaScript is easy, simply don’t make your product rely on JavaScript: – Death to href=“javascript:foo()” – Death to onclick=“foo()” – Who the hell ever told you to use onclick=“javascript:foo()” ? • Don’t mix HTML and JavaScript, use the DOM to access HTML. • The DOM is your API to the document. http://www.flickr.com/photos/jungle_boy/140233674/
  • 7. • Testing for DOM support is as easy: – Check that getElementById and is available. – If you still care about Opera 6 also test for createTextNode function init(){ if( document.getElementById && document.createTextNode ) // we have DOM, wahey! checkDependencies(); } }
  • 8. • Testing for the HTML you need is also easy: – Check that all the elements are available. function checkDependencies(){ var usedIds = ['nav','content']; var isOk = true; for(var i = 0; usedIds[i]!==undefined; i++) { if( !document.getElementById( usedIds[i] ) ){ isOk = false; } } return isOk; }
  • 9. • Testing for the HTML you need is also easy: – Check that all the elements are available. – Check that they also have the right child nodes function myNavStuff(){ var n = document.getElementById('nav'); if(n.getElementsByTagName('ul').length > 0){ // I got your code right here! } }
  • 10. • Testing for object availability – Simply test for any object before you access it var request; try{ request = new XMLHttpRequest(); }catch(error){ try{ request = new ActiveXObject(quot;Microsoft.XMLHTTPquot;); }catch(error){ return true; } }
  • 11. • Prepare for unreliable and flaky connections. – Set a timer to time out and abort the connection after a certain period has passed. – Define a success and failure case for any connection. – Make sure you avoid caching issues by setting an expired HTTP header on your Ajax calls
  • 12. • This is the “how” of progressive enhancement with JavaScript and Ajax. • The question however is why use JavaScript at all? • After all it can be turned off.
  • 13. • Instead we can use the amazing new trick called “CSS only solutions”. • Why bother with writing complex scripts when you can do the same with some easy lines of CSS? • Showing and hiding menus? #nav li ul { display:none } #nav li:hover ul { display:block }
  • 14. • Using CSS for behaviour is based on one trick, which is pseudo selectors like :hover, :active and :focus • These have several problems: – Some browsers only support them on interactive elements like links and buttons. – They have a strict on or off state. – and they fail for a certain user group…
  • 15. • Keyboard access support in HTML and browsers is bad. • Support for :active and :focus is even worse. • Which means that CSS only solutions with keyboard support turn out to be HTML soup nightmares (nesting tables inside links…)
  • 16.
  • 17. • In essence, CSS only solutions are a bit of a shifty character and you don’t know if you can trust them. • It is also debateable if CSS only solutions are in the end easier than JS solutions.
  • 18. • JavaScript has so many more options for you: – Real testing for support of objects – Real event handling including simulation of application keyboard handling (cursors instead of tabbing) – timeout() to allow for user errors – Creation of necessary markup on demand.
  • 19. • JavaScript has so many more options for you: – Test of available screen estate – Loading of extra content on demand http://www.flickr.com/photos/drewm/227562632/
  • 20.
  • 21. • Does this mean that only scripters should create interfaces and CSS is not needed? • Not at all, as first of all CSS can help JavaScript a lot. http://www.flickr.com/photos/drewm/225911999/in/set-507727/
  • 22. • Task: Hide all list items in the first UL – A lot of code, that one… window.onload = function(){ if(document.getElementById && document.createTextNode){ var uls = document.getElementsByTagName('ul'); if(uls.length > 0){ var lis = uls[0].getElementsByTagName('li'); for(var i = 0, j = lis.length; i < j; i++){ lis[i].style.display = 'none'; } } } }
  • 23. • Task: Hide all list items in the first UL – How about leaving the main job to the CSS parser? window.onload = function(){ if(document.getElementById && document.createTextNode){ var b = document.body; b.className += b.className ? ' dynamic' : 'dynamic'; } } <style type=quot;text/cssquot;> body.dynamic ul li{ display:none; } </style>
  • 24. • This also allows you to keep the whole look and feel of your scripts in the hands of the CSS maintainers. • All you need to do is make sure you communicate the class and ID names with them.
  • 25. • You achieve highest flexibility by separating those and the text labels out into own includes: slideshow.js slideshow-css.js slideshow-labels.js slideshow.css = { 'navigationID':'nav', 'contentID':'main', 'hide class':'hide' }
  • 26. • There is a danger in progressive enhancement with JavaScript though: • Be aware that what you enhance is as important as how you enhance it. • A solution that doesn’t really make sense shouldn’t be enhanced, but changed.
  • 27. • Useless progressive enhancement. Pointless name dropping Get on with it…
  • 28. • It is important to know your audience • It is important to keep up with technology as a lot of truths of the past are not applicable any longer.
  • 29. • Research what can be enhanced and how. • Example “connected select boxes”:
  • 30. • Research what can be enhanced and how. • Example “hcard to Googlemap”
  • 31. • So why isn’t progressive enhancement yet a common practice? http://www.flickr.com/photos/urlgirl/199044322/
  • 33. • Stockholm Syndrome • Enhanced interfaces don’t go down too well with the mainstream audience, we are used to waiting and things breaking. • Technologies are perceived as given, no need to improve them.
  • 34. • Monetary reasons • Progressive Enhancement costs money • As with any best practice there is no immediate tangible benefit
  • 35. • Show desire • You can help to change this • Look at things, and see how you can improve them • If need be, do it on the sly (hcard in Yahoo! Local)
  • 36. • Benefit from experience of others • A lot of tricks that helped us in the past can be brushed up and renewed now. • Example “lowsrc”
  • 37. • Keep your feelers out there. • Read up on technologies and what is done with them. • Hot: – http://www.w3.org/TR/aria- roadmap/ – http://www.whatwg.org/
  • 38. • Contact, subscribe, talk, share. • If you know something, please tell others: http://makemeaspeaker.com
  • 39. • Good progressive enhancement helps the user, and not the developer. – Automatic saving of drafts in email apps – Parallel upload of content while you can add meta data – Making it easy and fun to add content. – Preventing unnecessary steps. http://www.flickr.com/photos/radiofree/286343390/