understanding progressive enhancement - yuiconf2010

134
Write less - achieve more Understanding progressive enhancement with YUI

Upload: christian-heilmann

Post on 06-May-2015

6.089 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Understanding progressive enhancement - yuiconf2010

Write less - achieve more

Understanding progressive enhancement with YUI

Page 2: Understanding progressive enhancement - yuiconf2010

Progressive enhancement gets a bad rep these days.

Page 3: Understanding progressive enhancement - yuiconf2010

The reason is not that it is a bad idea.

Page 4: Understanding progressive enhancement - yuiconf2010

The reason is that it is misunderstood.

Page 5: Understanding progressive enhancement - yuiconf2010

Walled-off environments lead to progressive enhancement criticism.

Page 6: Understanding progressive enhancement - yuiconf2010

A Chrome extension will never have to work in IE6 - there is no point in that.

Page 7: Understanding progressive enhancement - yuiconf2010

iPad/iPhone/Air apps are much easier than building a web app.

Page 8: Understanding progressive enhancement - yuiconf2010

Staying in the comfort zone.

Page 9: Understanding progressive enhancement - yuiconf2010

Peripheral vision.

Page 10: Understanding progressive enhancement - yuiconf2010
Page 11: Understanding progressive enhancement - yuiconf2010

http://everytimezone.com/

Page 12: Understanding progressive enhancement - yuiconf2010

Technology annoyances are as much annoyances as physical ones.

Page 13: Understanding progressive enhancement - yuiconf2010
Page 14: Understanding progressive enhancement - yuiconf2010

HTML5 does not mean building apps for iPad, iPhone and Android.

Page 15: Understanding progressive enhancement - yuiconf2010

It is very easy to fall in this trap as developers.

Page 16: Understanding progressive enhancement - yuiconf2010

Everybody has JavaScript these days“

Page 17: Understanding progressive enhancement - yuiconf2010

I don’t really care about the numbers.

Page 18: Understanding progressive enhancement - yuiconf2010

To me, it is about celebrating the power of the web and software.

Page 19: Understanding progressive enhancement - yuiconf2010

The physical world can be a real pain.

Page 20: Understanding progressive enhancement - yuiconf2010
Page 21: Understanding progressive enhancement - yuiconf2010
Page 22: Understanding progressive enhancement - yuiconf2010

The most powerful tool of code is the if(){} statement.

Page 23: Understanding progressive enhancement - yuiconf2010

Take that “if” and make it part of your approach to development...

Page 24: Understanding progressive enhancement - yuiconf2010

...and you have progressive enhancement.

Page 25: Understanding progressive enhancement - yuiconf2010

Add after you tested for it.

Page 26: Understanding progressive enhancement - yuiconf2010

That way you never have the need to degrade gracefully.

Page 27: Understanding progressive enhancement - yuiconf2010

Building for the web means open development.

Page 28: Understanding progressive enhancement - yuiconf2010
Page 29: Understanding progressive enhancement - yuiconf2010

The web is a scary place.

Page 30: Understanding progressive enhancement - yuiconf2010

But it is so worth it!

Page 32: Understanding progressive enhancement - yuiconf2010

You can leave now - I don’t need you any longer to watch my videos!

““

Page 33: Understanding progressive enhancement - yuiconf2010

A constantly upgrading web?

Page 34: Understanding progressive enhancement - yuiconf2010

IE6+Large Organisations=BFF

http://www.hmg.gov.uk/epetition-responses/petition-view.aspx?epref=ie6upgrade

Page 35: Understanding progressive enhancement - yuiconf2010

Complex software will always have vulnerabilities and motivated adversaries will always work to discover and take advantage of them.  There is no evidence that upgrading away from the latest fully patched versions of Internet Explorer to other browsers will make users more secure.

Page 36: Understanding progressive enhancement - yuiconf2010

It is not straightforward for HMG departments to upgrade IE versions on their systems.  Upgrading these systems to IE8 can be a very large operation, taking weeks to test and roll out to all users.

Page 37: Understanding progressive enhancement - yuiconf2010

To test all the web applications currently used by HMG departments can take months at significant potential cost to the taxpayer. It is therefore more cost effective in many cases to continue to use IE6 and rely on other measures, such as firewalls and malware scanning software, to further protect public sector internet users.

Page 38: Understanding progressive enhancement - yuiconf2010
Page 39: Understanding progressive enhancement - yuiconf2010

And this is why we need progressive enhancement.

Page 40: Understanding progressive enhancement - yuiconf2010

Which is not “making it work for IE6”.

Page 41: Understanding progressive enhancement - yuiconf2010

Instead it is “test for support before you apply”

http://www.modernizr.com/

http://github.com/phiggins42/has.js

Page 42: Understanding progressive enhancement - yuiconf2010

Let’s go through a few examples of how progressive enhancement works.

Page 43: Understanding progressive enhancement - yuiconf2010

Pure JS environments.

Page 45: Understanding progressive enhancement - yuiconf2010
Page 46: Understanding progressive enhancement - yuiconf2010
Page 47: Understanding progressive enhancement - yuiconf2010
Page 48: Understanding progressive enhancement - yuiconf2010

Buttons?

Page 49: Understanding progressive enhancement - yuiconf2010

★ There is no real navigation happening here.

★ Everything is dependent on JS.

★ This is what buttons are for.★ And they are keyboard

accessible.

Page 50: Understanding progressive enhancement - yuiconf2010

Speeding up the process for the next visit.

Page 51: Understanding progressive enhancement - yuiconf2010
Page 52: Understanding progressive enhancement - yuiconf2010

Leaving fairyland and moving to the web...

Page 53: Understanding progressive enhancement - yuiconf2010

A very common approach to PE...

Page 54: Understanding progressive enhancement - yuiconf2010

Progressive enhancement by using a single page as the data container.

Page 56: Understanding progressive enhancement - yuiconf2010
Page 57: Understanding progressive enhancement - yuiconf2010

Pro:Always works - it is an HTML document

Con:Can result in huge sites (but gzip helps)

Page 58: Understanding progressive enhancement - yuiconf2010

Another approach: Using the backend as a simple API.

Page 61: Understanding progressive enhancement - yuiconf2010

Write the app as a simple form submit in PHP...

Page 62: Understanding progressive enhancement - yuiconf2010
Page 63: Understanding progressive enhancement - yuiconf2010

Then return chunks of HTML according to the parameters that came in.

Page 64: Understanding progressive enhancement - yuiconf2010
Page 65: Understanding progressive enhancement - yuiconf2010
Page 66: Understanding progressive enhancement - yuiconf2010

Override the requests with Ajax calls.

Page 67: Understanding progressive enhancement - yuiconf2010
Page 68: Understanding progressive enhancement - yuiconf2010

You maintain your whole app on the server and can monitor and cache like heck.

Page 69: Understanding progressive enhancement - yuiconf2010

And you still use the goodness that is JavaScript on top of that.

Page 70: Understanding progressive enhancement - yuiconf2010

Pro:Re-use of server includes as APIs possible.Least amount of JS and HTML generation in JS.

Con:Needs server component knowledge

Page 71: Understanding progressive enhancement - yuiconf2010

Every app works as a server-client connection in some way.

Page 72: Understanding progressive enhancement - yuiconf2010

The data has to come from some place.

Page 73: Understanding progressive enhancement - yuiconf2010

The myth of client-side security.

Page 74: Understanding progressive enhancement - yuiconf2010

Every JS developer sooner or later writes a form validator.

Page 75: Understanding progressive enhancement - yuiconf2010

This is always the killer argument of enemies of progressive enhancement.

Page 76: Understanding progressive enhancement - yuiconf2010

I spend a lot of time doing form validation in JavaScript - why should I repeat the same on the server side?

Page 77: Understanding progressive enhancement - yuiconf2010

Because there is no security in JavaScript!

Page 78: Understanding progressive enhancement - yuiconf2010

If all you do is validate in JS, attackers will have a field day with your server.

Page 79: Understanding progressive enhancement - yuiconf2010

Besides, there is no need to repeat validation rules.

Page 80: Understanding progressive enhancement - yuiconf2010
Page 81: Understanding progressive enhancement - yuiconf2010
Page 82: Understanding progressive enhancement - yuiconf2010

That way you validate on the server and you can use the same rules for your JS...

Page 83: Understanding progressive enhancement - yuiconf2010
Page 84: Understanding progressive enhancement - yuiconf2010

Form validation scripts are annoying.

Page 85: Understanding progressive enhancement - yuiconf2010

You need to access the right parts, read and write from the DOM, change styles and and and...

Page 86: Understanding progressive enhancement - yuiconf2010

You can leave it all to the server and still save your users a full page reload.

Page 87: Understanding progressive enhancement - yuiconf2010

Request type switching is the answer.

Page 88: Understanding progressive enhancement - yuiconf2010

JavaScript libraries add a special footprint to the server request when calling content via Ajax.

Page 89: Understanding progressive enhancement - yuiconf2010
Page 90: Understanding progressive enhancement - yuiconf2010

You can use this to send content to Ajax requests and other content to normal requests.

Page 91: Understanding progressive enhancement - yuiconf2010
Page 92: Understanding progressive enhancement - yuiconf2010

You can use this to render a form completely server side and just send a string back for each request.

http://github.com/codepo8/validationdemo

Page 93: Understanding progressive enhancement - yuiconf2010
Page 94: Understanding progressive enhancement - yuiconf2010

Filter inputs for nasties and include the rules.

Page 95: Understanding progressive enhancement - yuiconf2010

If the form has not been submitted, include the form code.

Page 96: Understanding progressive enhancement - yuiconf2010

Otherwise loop through the rules and check the data that was sent against them.

this is like /pattern/.test($(name).value)

Page 97: Understanding progressive enhancement - yuiconf2010

If there was an error - show the form again. Otherwise say thanks.

Page 98: Understanding progressive enhancement - yuiconf2010

The form itself is a simple HTML form doing all the dynamic rendering with PHP...

Page 99: Understanding progressive enhancement - yuiconf2010
Page 100: Understanding progressive enhancement - yuiconf2010

Check for the error array and if there is an error, show it. Otherwise show a * to indicate required field.

Page 101: Understanding progressive enhancement - yuiconf2010

Check if the form was sent via Ajax - if not, render the form element.

Page 102: Understanding progressive enhancement - yuiconf2010

If there was an error, say so. At the field show the error or the * SPAN.

Page 103: Understanding progressive enhancement - yuiconf2010

And all you then need to do in JavaScript is to override the form submission.

Page 104: Understanding progressive enhancement - yuiconf2010

And instead replace the innerHTML of the form on every submit.

Page 105: Understanding progressive enhancement - yuiconf2010

An example using YUI3...

Page 106: Understanding progressive enhancement - yuiconf2010

Load the IO and Node module.Define the configuration for the Ajax call.

On submission of the form load the validate.php file with the config and don’t send off the form.

Page 107: Understanding progressive enhancement - yuiconf2010

If the Ajax call was a success, replace the innerHTML of the form with the HTML returned from validate.php

Page 108: Understanding progressive enhancement - yuiconf2010

In addition to that, focus on the first element with an error message - this helps with assistive technology.

Page 109: Understanding progressive enhancement - yuiconf2010

If the Ajax call failed, send the form.

Page 110: Understanding progressive enhancement - yuiconf2010

Subscribe to the Ajax events.

Page 111: Understanding progressive enhancement - yuiconf2010

Build what works for everybody and then enhance.

Page 112: Understanding progressive enhancement - yuiconf2010

http://uk-house-prices.com/

Page 113: Understanding progressive enhancement - yuiconf2010

http://icant.co.uk/csscharts/

Page 114: Understanding progressive enhancement - yuiconf2010

For a lot of new developers, this looks like extra effort.

Page 115: Understanding progressive enhancement - yuiconf2010

Instead we produce low quality fallbacks.

Page 116: Understanding progressive enhancement - yuiconf2010

This is not the web I want people to get!

Page 117: Understanding progressive enhancement - yuiconf2010

Bah! PHP...

Page 118: Understanding progressive enhancement - yuiconf2010

Progressive Enhancement is a huge part of the YUI philosophy.

Page 119: Understanding progressive enhancement - yuiconf2010
Page 120: Understanding progressive enhancement - yuiconf2010

http://www.yuiblog.com/blog/2010/09/29/video-glass-node/

Page 121: Understanding progressive enhancement - yuiconf2010

Today’s widgets are already tomorrow’s native controls.

Page 122: Understanding progressive enhancement - yuiconf2010

type=”range”

type=”date”

type=”color”

type=”file”

<datalist>

Page 123: Understanding progressive enhancement - yuiconf2010

Re-use of learnings.

Page 124: Understanding progressive enhancement - yuiconf2010

CSS3Animation

Transitionand

Page 125: Understanding progressive enhancement - yuiconf2010
Page 126: Understanding progressive enhancement - yuiconf2010

Capability based loading = win!

Page 127: Understanding progressive enhancement - yuiconf2010

The future of web apps is being forged right now.

Page 128: Understanding progressive enhancement - yuiconf2010

HTML5

Page 129: Understanding progressive enhancement - yuiconf2010
Page 130: Understanding progressive enhancement - yuiconf2010

Be part of the movement for a better web for all.

Page 131: Understanding progressive enhancement - yuiconf2010

HTML5 means moving from hacks to web applications.

Page 132: Understanding progressive enhancement - yuiconf2010

So let’s build a working web for all.

Page 133: Understanding progressive enhancement - yuiconf2010

Come and talk to us, to Google, to Apple, to Mozilla, to Opera, to Microsoft...Your input matters!

Page 134: Understanding progressive enhancement - yuiconf2010

Christian Heilmann http://wait-till-i.com http://developer-evangelism.com http://twitter.com/codepo8

Thanks!