Jeremy Keith — Progressive Enhancement with Hijax

Public health warn­ing – there will be code!

Taking notes on a code-​​heavy pre­sen­ta­tion is a dif­fi­cult chal­lenge; I strongly rec­om­mend you grab Jeremy’s pre­sen­ta­tion slides to accom­pany these notes.

  • AJAX is often treated as all or noth­ing tech­nol­ogy, much like plu­g­ins – either you have it, or you don’t.
  • Ideally you want to have one site that pro­vides both AJAX and non-​​AJAX facil­i­ties; this is pro­gres­sive enhancement.
  • Progressive enhance­ment begins with seman­ti­cally mean­ing­ful con­tent; you then add the pre­sen­ta­tion layer and the behav­iour layer.
  • Stylesheet must be kept exter­nal; inline styles are no bet­ter than font tags.
  • JavaScript pseudo-​​protocol is evil; always has been. JavaScript is not a pro­to­col, pseudo or otherwise.
  • Inline script, much like inline CSS is a main­te­nance night­mare and should be avoided at all cost. Both pre­sen­ta­tion and behav­iour lay­ers can be kept exter­nal; there’s no rea­son you can’t.
  • Jeremy shows a JavaScript func­tion that scans through the DOM look­ing for links with a class of “help” and makes them open in a popup rather than the cur­rent win­dow. This is the alter­na­tive to inline event han­dlers. This is unob­tru­sive JavaScript.
  • Don’t use global vari­ables kids; they’re bad
  • Next code walk­through involves cre­at­ing an instance of an XMLHttpRequest object; set­ting up the response han­dler and call­ing the object’s open method (define POST/​GET, URL and whether it should be an asyn­chro­nous request)
  • The readyS­tate prop­erty: has 4 states, but only the value of 4 really mat­ters to us; that’s the one that says I’m done, lets rock!
  • Returns either respon­seXML or respon­se­Text; respon­seXML MUST have the cor­rect mime type from the server, rep­son­se­Text can be text, JSON, HTML, what­ever you want.
  • Progressive enhance­ment with AJAX is very much pos­si­ble – Hijax is Jeremy’s buzz­word for it.
  • Step one of Hijax devel­op­ment: build a web­site using tra­di­tional page refreshes.
  • Step two: Hijack (get it?) the links and forms using unob­tru­sive JavaScript
  • Server require­ments: back-​​end archi­tec­ture needs to be mod­u­lar; pages are then made by join­ing those mod­ules together when needed. You need to plan for AJAX when deis­gn­ing the back-​​end, but don’t imple­ment AJAX on the front-​​end until the very end (end)
  • Visual feed­back is incred­i­bly impor­tant; if adding ‘field is required’ errors via JavaScript, add it to the &ltla­bel> ele­ment to help out screen readers.
  • Jeremy demon­strates exam­ples of Hijax includ­ing shop­ping cart and con­tact form. The data the server needs is always con­tained within the form or the link query string. These val­ues are grabbed by JS and the script returns false on suc­cess; thereby can­celling the default action for a link click or form submission
  • The browser is no place for busi­ness logic — use the XMLHttpRequest object like a dumb waiter; it is just to carry data around, not to do any heavy lift­ing with that data.
  • The browser is an unpre­dictable envi­ron­ment […] you con­trol your server, do all your data pro­cess­ing there
  • Jeremy rec­om­mends we don’t even use JavaScript table sort­ing scripts.
  • Key ben­e­fits of Hijax: no need to build two ver­sions; no dupli­ca­tion of logic (eg: form val­i­da­tion done exclu­sively on the browser); Keeps your logic where it should be – on your server; keeps your JavaScript file size down.

3 responses to “Jeremy Keith — Progressive Enhancement with Hijax”:

  1. Sounds very interesting!

    Do you know if Jeremy has released any code to do this hijax­ing with?

  2. […] I strongly sug­gest you head over to the WebDirections web­site to have a look at Jeremy’s pre­sen­ta­tion on the topic with a spe­cial focus on AJAX. Apart from the slides avail­able at the site I would also rec­om­mend to have a quick peek at the live blog notes that Andrew posted during/​after Jeremy’s presentation. […]

  3. Troels, there are var­i­ous snip­pets of Hijax exam­ples around the inter­world­web­net. Jeremy’s “DOM Scripting” book intro­duces the idea nicely, but his forth­com­ing title “Bulletproof Ajax” is likely to evan­ge­lise the hijax con­cept with code examples.

Your opinion:

XHTML: You're allowed to use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>