"Progressive enhancement" involves designing sites in a way that allows everyone to access the basic content of a web page while also providing enhanced versions to visitors with faster bandwidth or more advanced browsers. In this session, Aaron Gustafson covers the current best practice in this critical aspect of web standards development. Staring with an introduction to the topic, Aaron will walk you through the best ways to apply style and behavior to your pages, providing concrete examples and implementations that you can start using right away.
26. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Rely on your baseline
robust JavaScript
User Experience
some JavaScript
robust CSS
some CSS
XHTML & HTTP
WEB DESIGN WORLD 17
62. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Event Listening
window.onload = handleExternalLinks;
function handleExternalLinks(){
var server = document.location.hostname;
var anchors = document.getElementsByTagName(quot;aquot;);
var i, href;
for( i=0; i < anchors.length; i++ ){
href = anchors[i].href;
if( href.indexOf(quot;http://quot; + server) == -1 &&
href.indexOf(quot;https://quot; + server) == -1 ){
// HREF is not a file on my server
anchors[i].onclick = function(){
newWin( this.href );
};
}
}
}
WEB DESIGN WORLD 42
67. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
No style before its time
<div id=quot;mainquot; class=quot;tabbedquot;>
becomes
<div id=quot;mainquot; class=quot;tabbed-onquot;>
WEB DESIGN WORLD 47
68. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
No style before its time
Default Activated
add “-on” to the class .tabbed .tabbed-on
add an activation class .auto-submit .auto-submit.active
change the form of the class .replace-me .replaced
WEB DESIGN WORLD 47
70. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look for methods
function someFunction(){
if( !document.getElementsByTagName ) return;
// code that uses document.getElementsByTagName()
...
}
WEB DESIGN WORLD 49
71. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look for methods
function someFunction(){
if( !document.getElementsByTagName ||
!document.getElementById ) return;
/* code that uses document.getElementsByTagName()
and document.getElementById() */
}
WEB DESIGN WORLD 50
72. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look for elements
function someFunction(){
if( !document.getElementsByTagName ||
!document.getElementsByTagName( 'p' ) ) return;
/* code that uses document.getElementsByTagName()
and requires the presence of a P element */
...
}
WEB DESIGN WORLD 51
73. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look for identified elements
function someFunction(){
if( !document.getElementById ||
!document.getElementById( 'content' ) ) return;
// code that requires the presence of #content
...
}
WEB DESIGN WORLD 52
74. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look for objects
function someFunction(){
if( typeof( Prototype ) == 'undefined' ) return;
// code that uses Prototype
...
}
WEB DESIGN WORLD 53
75. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look for object versions
function someFunction(){
if( typeof( Prototype ) == 'undefined' ||
parseFloat( Prototype.Version ) < 1.5 ) return;
// code that uses Prototype 1.5 or higher
...
}
WEB DESIGN WORLD 54
76. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Look before you leap
window.onload = function(){
if( document.getElementsByTagName &&
document.getElementById ){
someFunction();
}
};
WEB DESIGN WORLD 55
80. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Traditional approach
<h1>Pumpkin Pie</h1>
<div class=quot;containerquot;>
<div class=quot;sectionquot;>
<h2>Overview</h2>
<img src=quot;pie.jpgquot; alt=quot;quot;>
<p>Whether you're hosting a festive party or a casual get-together with
friends, our Pumpkin Pie will make entertaining easy!</p>
...
</div>
...
<ul class=quot;tabsquot;>
<li><a href=quot;#quot;>Overview</a></li>
<li><a href=quot;#quot;>Ingredients</a></li>
<li><a href=quot;#quot;>Directions</a></li>
<li><a href=quot;#quot;>Nutrition</a></li>
</ul>
</div>
WEB DESIGN WORLD 60
86. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
The actual source
<h1>Pumpkin Pie</h1>
<div class=quot;tabbedquot;>
<h2>Overview</h2>
<img src=quot;pie.jpgquot; alt=quot;quot; />
<p>Whether you're hosting a festive party or a casual get-together with friends,
our Pumpkin Pie will make entertaining easy!</p>
...
<h2>Ingredients</h2>
<ul>
<li>1 (9<abbr title=quot;inchquot;>in</abbr>) unbaked deep dish pie crust</li>
<li>! cup white sugar</li>
<li>1 <abbr title=quot;teaspoonquot;>tsp</abbr> ground cinnamon</li>
...
</ul>
<h2>Directions</h2>
...
</div>
WEB DESIGN WORLD 65
90. FUNDAMENTAL PROGRESSIVE ENHANCEMENT
Example: Collapsing Form
Goal: to create a search form with optional advanced filters.
By default the optional filters should be hidden, but users
should be able to show and hide them as they need to.
WEB DESIGN WORLD 69
101. Slides available at
http://slideshare.net/AaronGustafson
This presentation is licensed under
Creative Commons
Attribution-Noncommercial-Share Alike 3.0
flickr Photo Credits
“MacBook Pro” by dansays
“M&M” by madame.furie
“Six-layered chocolate cake” by PetitPlat
“Day 486 / 365 - Late Night High Level Coding” by JasonRogers
“Leghoul” by oskay
“Risk” by andyburnfield
“fr tom” by ambery
“CORNERSTONE” by spike55151
“Freedom” by drp
“Headphone” by Giando
“Shout, shout” by hebedesign
“The writing is on the wall” by thus spake drake
“Tiger Leaping Gorge - Ram” by josh-n
“some assembly required” by massdistraction