150
Modern Web Technologies (and why you should care) Reuven M. Lerner • [email protected] Megacomm February 15 th , 2012

Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Embed Size (px)

Citation preview

Page 1: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Modern Web Technologies (and why

you should care)Reuven M. Lerner • [email protected]

MegacommFebruary 15th, 2012

Page 2: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Who am I?

• Web developer since 1993

• Software architect/consultant/trainer

• Linux Journal columnist since 1996

• Mostly Ruby on Rails + PostgreSQL, but also Python, jQuery, MySQL, and more...

• PhD candidate at Northwestern University

Page 3: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How does the Internet (TCP/IP) work?

Client Server“Socket”

Port Port

Page 4: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How does the Internet (TCP/IP) work?

Client Server“Socket”

Client opens connection

Port Port

Page 5: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How does the Internet (TCP/IP) work?

Client Server“Socket”

Client opens connection

Port Port

Server accepts connection

Page 6: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Protocols

• Communication standards built on top of TCP/IP, typically text-based

• SMTP (e-mail)

• FTP (file transfer)

• NNTP (transfer of “news” articles)

Page 7: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

WWW:Three technologies

• Markup format: HTML

• URL: protocol + server + port + doc

• Protocol: HTTP

Page 8: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How the Web works

Browser Server

Page 9: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How the Web works

Browser Server

HTTP Request

Page 10: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How the Web works

Browser Server

HTTP Request

HTTP Response

Page 11: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

How the Web works

Browser Server

HTTP Request

HTTP Response

Stateless — after the response is sent, the connection is broken and forgotten

Page 12: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Simple request

Browser Server

Page 13: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Simple request

Browser Server

GET /

Page 14: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Simple request

Browser Server

GET /

200 OK<html><head>...</head><body>...</body></html>

Page 15: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Not found?

Browser Server

Page 16: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Not found?

Browser Server

GET /blahblah

Page 17: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Not found?

Browser Server

GET /blahblah

404 Not found

Page 18: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Three things are certain:

Death, taxes, and lost data.

Guess which has occurred.

— David Dixon, Salon magazine contest

Page 19: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Submitting forms

Browser Server

Page 20: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Submitting forms

Browser Server

POST /loginname=reuven&password=secret

Page 21: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Submitting forms

Browser Server

POST /loginname=reuven&password=secret

200 OK<html>...<p>Thank you!</p>...</html>

Page 22: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Document = request

• If an HTML page contains images, then each is retrieved in a separate HTTP request

• Page with 30 images = 31 HTTP requests

• Page with 20 images, 10 JavaScript files, and 5 CSS files = 36 HTTP requests

Page 23: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 24: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Idea: Lie to the browser

• Don’t return a document to the user

• Rather, run a program when the user makes a request, and send the program’s output

• If the output is in HTML, then the browser will show it no differently than a static doc

Page 25: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Just in time production

• Wait as long as possible to create pages for the user

• Ideally, create them when the user requests them

• “Mass customization”

Page 26: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Dynamic document

Browser Server

Page 27: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Dynamic document

Browser Server

GET /

Page 28: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Dynamic document

Browser Server

GET /

200 OK<html><head>...</head><body>...</body></html>

Page 29: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Dynamic document

Browser Server

GET /

200 OK<html><head>...</head><body>...</body></html>

Program output

Page 30: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 31: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 32: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

What we return

• Usually HTML

• Image (e.g., stock graphs, Google Analytics)

• Word/Excel doc (e.g., from Google docs)

• PDF (e.g., PDF reports)

• XML, JSON (for computers, not people)

• Basically, any defined MIME type

Page 33: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

Computer A (browser)

Page 34: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

GET /

Computer A (browser)

Page 35: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

GET /

200 OK<some-xml><talk>JWP</talk></some-xml>

Computer A (browser)

Page 36: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

GET /

200 OK<some-xml><talk>JWP</talk></some-xml>

Page 37: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

GET /

200 OK<some-xml><talk>JWP</talk></some-xml>

Page 38: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

GET /

200 OK<some-xml><talk>JWP</talk></some-xml>

Page 39: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

APIs and mobile apps

Computer B (server)

GET /

200 OK<some-xml><talk>JWP</talk></some-xml>

Page 40: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

What is a Web app?

• Receives its inputs via HTTP

• Sends its output via HTTP

• That’s it! A Web application can do anything you want, within these limits

Page 41: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

That’s it!

• Now you understand how the Web works.

• Really, that’s it.

• Go home.

Page 42: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

OK, perhaps not...

• How do we write these programs?

• Where (and how) do we store user data?

• How have the underlying technologies (URLs, HTTP, and HTML) advanced?

Page 43: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Early Web applications

• First server-side programs were in C

• They were compiled into binaries

• So you had the CGI source (cgi-src) directory...

• ... and the CGI binary (cgi-bin) directory

Page 44: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

• No explicit compilation

• Cross platform

• Built-in, powerful text functions

• Do a lot in a little bit of code

• Perl, Python, PHP, Ruby

• Typically open source

“Scripting” languages

Page 45: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Frameworks

• DRY (Don’t repeat yourself)

• Get rid of the drudgery

• Concentrate on your business, rather than worrying about common Web issues

Page 46: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

MVC paradigm

• Most modern frameworks use MVC

• From Smalltalk in the 1980s!

• Model — communicates with database

• View — HTML/JavaScript/CSS for user

• Controller — handles requests

• Clear division of labor

Page 47: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Web frameworks in dynamic languages

• Programmer speed trumps execution speed

• Community support

• Plugins for commonly requested features

• Create a domain-specific language (DSL) for your specific needs

Page 48: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ruby on Rails

• Ruby language

• Rails Web app framework (MVC)

• Designed for writing Web DSLs

• “Convention over configuration”

• Thousands of little improvements

• ActiveRecord — ORM

Page 49: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Person model

class Person < ActiveRecord::Base

end

Page 50: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Where’s the definition?

• The computer takes care of it automatically

• ActiveRecord knows what columns you have defined, and what their types are

• (More on columns later)

• Only write things that cannot be understood automatically

Page 51: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Not only Rails

• Python (Django)

• PHP (Symfony)

• Perl (Catalyst)

• Groovy (Grails)

• Even if you don’t use Ruby on Rails, you have benefitted from its “opinions”

Page 52: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Plugins

• Rails (and other systems) have open-source plugins to handle common issues

• Authentication

• E-commerce

• Social networking

• Don’t write these yourself! Customize existing code that has proved itself

Page 53: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Storage

• Applications are great!

• But what if we want to store information about our users?

• Name, e-mail address, account balance

• We could use text files, but most people will use a database

Page 54: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

What is a database?

Database

Store data confidently

Retrieve data flexibly

Page 55: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Relational databases

Define tables, store data in them

Database

Retrieve data from related tables

Page 56: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Relational database

SQL goes hereCREATE TABLE

INSERTUPDATEDELETE

Database

Page 57: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Relational databases

• Everything is stored in 2-dimensional tables

• Data should appear only once (normalized)

• “Join” tables to connect tables

• Technology is extremely robust, fail-safe

• Not all data is a good fit for this paradigm

Page 58: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

id first_name last_name phone

1 Reuven Lerner 054-496-8405

2 Charlie Kalech 02-671-9918

Page 59: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

id first_name last_name email

1 Reuven Lerner [email protected]

2 Charlie Kalech [email protected]

person_id phone_number

1 054-496-8405

1 847-230-9795

2 02-671-9918

2 054-803-3356

2 501-629-8620

Page 60: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

id first_name last_name email

1 Reuven Lerner [email protected]

2 Charlie Kalech [email protected]

id type

1 work

2 mobile

3 fax

4 home

person_id phone_number_type_id phone_number

1 2 054-496-8405

1 1 847-230-9795

2 1 02-671-9918

2 2 054-803-3356

2 3 501-629-8620

Page 61: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

id first_name last_name email

1 Reuven Lerner [email protected]

2 Charlie Kalech [email protected]

id type

1 work

2 mobile

3 fax

4 home

person_id phone_number_type_id phone_number

1 2 054-496-8405

1 1 847-230-9795

2 1 02-671-9918

2 2 054-803-3356

2 3 501-629-8620

SELECT P.first_name, P.last_name, P.email, PN.phone_number, PNT.typeFROM People P, Phone_Numbers PN, Phone_Number_Types PNTWHERE PN.person_id = P.id AND PNT.id = PN.phone_number_type_id

Page 62: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Another language!

• SQL is the language of relational databases

• So a Web app will use a language (e.g., Ruby, Python, or PHP) + SQL

• Or use an ORM, which automatically translates your language into SQL

Person.first.phone_number

Page 63: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser

Page 64: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser

HTTP Request

Page 65: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser Server

HTTP Request

Page 66: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser Server

HTTP Request

Page 67: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser Server

HTTP Request

Database

Page 68: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser Server

HTTP Request

Database

Page 69: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Extending our diagram

Browser Server

HTTP Request

HTTP Response

Database

Page 70: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Popular databases

• PostgreSQL (my favorite)

• MySQL

• Microsoft SQL Server

• Oracle

• Most popular: SQLite!

Page 71: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Scaling problems

• Lots of requests?

• Optimize

Page 72: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Scaling problems

• Lots of requests?

• Optimize

• Even more requests?

• Buy a bigger server

Page 73: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Scaling problems

• Lots of requests?

• Optimize

• Even more requests?

• Buy a bigger server

• What next?

• Panic! (Or spend lots of money)

Page 74: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Sharding

• Split your data across multiple databases

• This works, but...

• Requires rewriting a lot of code

• Maintenance is a big issue

• Re-sharding as each server gets overwhelmed can be expensive, time-consuming

Page 75: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Non-relational databases

• Don’t store things in tables!

• Don’t pre-define a schema

• No SQL!

• Indeed, known as “NoSQL” databases

• Only common factor: No SQL, non-relational

Page 76: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Examples

• Key-value stores

• e.g., Memcached, Redis, Tokyo Cabinet

• Columnar databases

• e.g., Cassandra

• Document databases

• e.g., MongoDB, CouchDB

Page 77: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

MapReduce / Hadoop

• Google and Yahoo do it like this:

• Split data across many servers

• Run a function on all of those servers

• Collect the results

• Display to the user!

• (Too slow? Add more servers!)

Page 78: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

NoSQL: Good news

• Often easier to administer, configure

• Scaling to multiple servers is a no-brainer

• No new programming language (SQL)!

• Better fit for certain kinds of data

• Better performance than a relational DB

• Lots of options to choose from!

Page 79: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

NoSQL: Bad news

• Speed is in the eye of the beholder

• Is “eventually consistent” good enough?

• Non-normalized data — ugh!

• Reporting can be harder

• Less tested than relational databases

• Can you trust your data to them?

Page 80: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Meanwhile...

• Our browsers are displaying HTML

• HTML had several problems:

• Standardized set of tags

• Making it easy for programs to parse

• Semantic, display content were mixed

Page 81: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

HTML standards

• HTML — several versions, several standards, none universally accepted

• XML — lets us create HTML-like languages, for computer conversations

• XHTML — HTML for pedantic people

• It was a big mess!

Page 82: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

HTML5

• Relaxes much of the formality of XHTML, while remaining easy for computers to read

• Backward compatible to a large degree

• Adds a number of tags for better semantics

• Best of all: Lots of new JavaScript goodies

• More on this in a moment

Page 83: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

HTML5 declaration

Page 84: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

HTML5 declaration

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Page 85: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

HTML5 declaration

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!DOCTYPE html>

Page 86: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 87: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 88: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 89: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012
Page 90: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

New “email” tag

<input type=”text” name=”email” />

<input type=”email” name=”email” />

Page 91: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

New “url” tag

<input type=”text” name=”url” />

<input type=”url” name=”url” />

Page 92: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

New “date” tag

<input type=”date” name=”date” />

Page 93: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Color picker!

<input type=”color” name=”color” />

Page 94: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

And more

• Validation — built-in validation of form element inputs, via regular expressions

• No more JavaScript plugins!

• Sliders — more natural numeric inputs

• Canvas — draw any picture you might like, and detect/change it with software

• Hints in text fields (e.g., “search”)

Page 95: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

My favorite

• Private data in attributes!

• Any attribute starting with “data-” is considered valid

• A great way to stash information inside of HTML elements without violating standards

Page 96: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Oh, yeah

• These don’t all work.

• Many of them don’t work on any browser

• Most work on only some browsers.

• What to do? Wait. Or use Modernizr, which uses JavaScript to detect features.

• If a feature isn’t there, you can fall back

Page 97: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS

• Cascading Style Sheets

• Split semantic markup from presentation

• One CSS file can apply to an entire site

• No more “style” tags in your text!

• Easy to move place things, create effects

Page 98: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ids are unique

<p id=”important”>Agenda</p>

p#important {

font-size: 13p;

font-weight: bold;

}

Page 99: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Classes can repeat

<p class=”important”>Agenda</p>

<p class=”important”>Lunch</p>

p.important {

font-size: 13p;

font-weight: bold;

}

Page 100: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

It gets better

• You can set styles for when the user’s mouse hovers over or clicks on an element

• In other words: Cheap animation!

• Many uses of JavaScript (e.g., some menus) can now be done with simple CSS

• You can make beautiful sites with CSS

Page 101: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS3: Cool effects

• Rounded corners

• Transparency

• Text shadows and drop shadows

• Gradients

Page 102: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS3: Cool selectors

• If you love regular expressions, then these selectors will be second nature to you:

p[id=”foo”] { background: green}

p[id^=”foo”] { background: green}

p[id$=”foo”] { background: green}

p[id*=”foo”] { background: green}

Page 103: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS3: Cool selectors

• If you love regular expressions, then these selectors will be second nature to you:

p[id=”foo”] { background: green}

p[id^=”foo”] { background: green}

p[id$=”foo”] { background: green}

p[id*=”foo”] { background: green}

Equals

Page 104: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS3: Cool selectors

• If you love regular expressions, then these selectors will be second nature to you:

p[id=”foo”] { background: green}

p[id^=”foo”] { background: green}

p[id$=”foo”] { background: green}

p[id*=”foo”] { background: green}

Starts with

Page 105: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS3: Cool selectors

• If you love regular expressions, then these selectors will be second nature to you:

p[id=”foo”] { background: green}

p[id^=”foo”] { background: green}

p[id$=”foo”] { background: green}

p[id*=”foo”] { background: green}

Ends with

Page 106: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

CSS3: Cool selectors

• If you love regular expressions, then these selectors will be second nature to you:

p[id=”foo”] { background: green}

p[id^=”foo”] { background: green}

p[id$=”foo”] { background: green}

p[id*=”foo”] { background: green}Contains

Page 107: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

OK, that’s nice.

• But really, the big news with HTML5 doesn’t have to do with HTML at all.

• Instead, it has to do with JavaScript.

• Remember JavaScript?

• It’s the programming language that we love to hate. (At least, I used to.)

Page 108: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

JavaScript

• Originally “LiveScript,” a language that executes programs in the browser

• Renamed “JavaScript” when an unrelated language (“Java”) stole the thunder

• Renamed (officially) ECMAScript for standardization purposes

• No one actually calls it this

Page 109: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

HTML5 turns the browser into a smart, powerful, networked application platform.JavaScript makes it

possible.

Page 110: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Powerful? Huh?

• Didn’t I just say that I love to hate JavaScript?

• And then I said that it was powerful?

• What gives?

Page 111: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

JavaScript isthe new hotness

• Browsers are competing for fastest, best

• Google’s V8

• Mozilla’s TraceMonkey (and JägerMonkey)

• Safari’s Nitro

• IE’s Chakra

• JavaScript is faster, more stable than ever!

Page 112: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Server-side JavaScript!

• The latest JavaScript development

• Run it on your server!

• Why? Because it’s super-fast

Page 113: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Also: frameworks

• Remove the drudgery of JavaScript

• Handle differences between browsers

• Make it easy to perform common tasks

• Lots of plugins available

• For me, it’s the difference between pain and pleasure when working with JavaScript

Page 114: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

JavaScript frameworks

• Dojo

• YUI

• MooTools

• Prototype

• jQuery (the 900-pound gorilla)

Page 115: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

jQuery

• jQuery has taken the world by storm

• Super-easy to use

• Extremely fast

• Open source (of course!)

• Easy to write plugins

• Lots of plugins are available

Page 116: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

• One reason for JavaScript libraries: Ajax!

• Make HTTP requests from within the page

• No refresh! Just get results from the server, and modify the page accordingly

• This has revolutionized our view of Web pages

Page 117: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

Page 118: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

POST /loginname=reuven&password=secret

Page 119: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

POST /loginname=reuven&password=secret

200 OK<html>...<p>Thank you!</p>...</html>

Page 120: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

POST /loginname=reuven&password=secret

200 OK<html>...<p>Thank you!</p>...</html>

Page 121: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

POST /loginname=reuven&password=secret

200 OK<html>...<p>Thank you!</p>...</html>

Page 122: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

POST /loginname=reuven&password=secret

200 OK<html>...<p>Thank you!</p>...</html>

Page 123: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax

Browser Server

POST /loginname=reuven&password=secret

200 OK<html>...<p>Thank you!</p>...</html>

Page 124: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Ajax isn’t everything

• What if I want a chat application, or something else that stays open?

• What if I want to execute more than one JavaScript function at a time?

• What if I want to store things locally?

• HTML5 provides all this — and more!

Page 125: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Canvas

• A complete drawing area, in your browser!

• Use JavaScript to:

• Draw arbitrary shapes

• Detect the mouse

• Detect the drawing

• The end of Flash? Maybe...

Page 126: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Geolocation

• Your browser can know where you are!

• It can send this info to the server

• It’s not perfect, but still pretty good

• To avoid privacy issues, users are always asked if their location should be shared

Page 127: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Inter-page communication

• Modern Web apps can span multiple pages

• HTML5 makes it easy for two pages (from the same server) to communicate

• The receiver knows which server sent the data — so it can filter incoming messages, as well as screen them for security

Page 128: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Web sockets

• This is potentially the biggest deal of all

• Ajax allows for server connections. But:

• High overhead

• Stateless

• Web sockets have low overhead, and they stay open as long as you need!

Page 129: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Using Web sockets

Page 130: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Using Web socketsvar weatherSocket = new WebSocket("ws://localhost:8080");

Page 131: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Using Web socketsvar weatherSocket = new WebSocket("ws://localhost:8080");

weatherSocket.onopen = function(e) { alert("Opened weather socket");};

Page 132: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Using Web socketsvar weatherSocket = new WebSocket("ws://localhost:8080");

weatherSocket.onopen = function(e) { alert("Opened weather socket");};

weatherSocket.onmessage = function(e) { alert("Got message: " + e.data);};

Page 133: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Using Web socketsvar weatherSocket = new WebSocket("ws://localhost:8080");

weatherSocket.onopen = function(e) { alert("Opened weather socket");};

weatherSocket.onmessage = function(e) { alert("Got message: " + e.data);};

weatherSocket.onclose = function(e) { alert("Closing socket..."); };

Page 134: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

What can sockets do?

• Chat servers

• Stock feeds

• Teleconferencing

• Who knows?

• Remember, HTTP was only invented after sockets had been around for 15 years

Page 135: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Web workers

• Execute more than one thing at a time

• In other words: You can run JavaScript functions in the background

• Process text

• Open Web sockets

• Perform calculations

Page 136: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Local storage

• Now Web apps can store data

• A little database of name-value pairs

var foo = localStorage.getItem("bar");

localStorage.setItem("bar", foo);

Page 137: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Local storage

• Now Web apps can store data

• A little database of name-value pairs

var foo = localStorage.getItem("bar");

localStorage.setItem("bar", foo);

var foo = localStorage["bar"];

Page 138: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Local storage

• Now Web apps can store data

• A little database of name-value pairs

var foo = localStorage.getItem("bar");

localStorage.setItem("bar", foo);

var foo = localStorage["bar"];

localStorage["bar"] = foo;

Page 139: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Media

• Standard (well, sort of) ways to play audio and video

• No more Flash!

• Problem: No one format is supported by all browsers

Page 140: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Rich client-side frameworks

• Backbone

• Ember

Page 141: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Design frameworks

• Twitter bootstrap

• Blueprint

• Compass

Page 142: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Don’t forget mobile!

• iOS and Android are growing massively

• Web site vs. native app?

• (Ask Jakob Nielsen — for now, apps are better, but that won’t last for long)

• Ignore these users at your peril

Page 143: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Want a Web app?

• It used to be:

• “What operating system, language, and database will I use?”

• Or:

• “How can I produce an interesting Web site?”

Page 144: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Now it’s:

• What experience do we want to give people?

• What will they be using to access our system?

Page 145: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Those lead to a wide variety of questions:

• What server language and framework? JavaScript framework? Hosted or cloud?

• What type of database (relational, NoSQL)? Which one? Hosted or cloud?

• Do we offer an API? A mobile app? Both?

• Which HTML5 features do we want to use, and how do we gracefully degrade?

Page 146: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

The key takeaway

• Web sites are far more than just static text, blogs, or forums

• They’re full-fledged software applications

• Take advantage of these technologies, and you can create a fabulous experience

• (Don’t take advantage of them, and your competitors will!)

Page 147: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Oh, yeah: Testing

• Automated testing is amazing

• Your Web site should use it

• Most modern frameworks support some sort of testing — if not, change framework

• Catch dumb bugs and issues before your customers do!

• Faster and cheaper than people

Page 148: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

My brain is too small!

• Yes, there’s a lot to learn

• Most of it can wait a little bit

• There are oodles of tutorials and books that can help you

• Besides a lot of this is still highly transitional

Page 149: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Whew!

• There’s a lot to the modern Web

• It’s fun and exciting, and continues to move forward at breakneck speed

• Understanding as many of these parts as possible will help you make better decisions, and better applications!

Page 150: Modern Web technologies (and why you should care): Megacomm, Jerusalem, February 2012

Any questions?

• Call me: 054-496-8405

• E-mail me: [email protected]

• Interrupt me: reuvenlerner (Skype/AIM)