End-to-end HTML5 APIs - The Geek Gathering 2013

41
End-to-end HTML5 APIs Alexandre Morgaut Osijek, Croatia October 12th, 2013

description

REST seven’s rule was “Code on Demand,” meaning the ability for the server to deliver code able to run on the client, and the recommended language was JavaScript. Some, to use the same code everywhere, tried to do it with Java, or .NET (ActiveX). None of them had long life success in browsers. HTML5 and offline support contributed in the creation of a bunch of APIs which only made sense on server-side in first place: File/FileSystem, Workers, Sockets, Storage/Session, Blob, ImageData. Almost all those APIs, including the not that young XMLHttpRequest, have been designed to be usable via either synchronous or asynchronous APIs. We have today the opportunity to write code really able to either on the server and on the client and then have consistent behaviors and security rules. We can expect interoperable code/libraries/modules, save a lot of developing and debugging time, get more people involved in code we need. Discover already existing opportunities, see some of them working, and envision what the future can come with.

Transcript of End-to-end HTML5 APIs - The Geek Gathering 2013

Page 1: End-to-end HTML5 APIs - The Geek Gathering 2013

End-to-end HTML5 APIs

Alexandre MorgautOsijek, CroatiaOctober 12th, 2013

Page 2: End-to-end HTML5 APIs - The Geek Gathering 2013

PresentationW3C AC member

Web Architect

JS Expert

REST Lover

NoSQL Fanboy

W3C “jseverywhere“ community group

@amorgaut

Page 3: End-to-end HTML5 APIs - The Geek Gathering 2013

AgendaThe Web & JavaScript

Web standards

Server-Side JavaScript

HTML5

Remote Debugging

Present & Future

Page 4: End-to-end HTML5 APIs - The Geek Gathering 2013

The Web & JavaScript

Page 5: End-to-end HTML5 APIs - The Geek Gathering 2013

The WebWWW: WorldWideWeb (Hypertext Project)

UDI: Uniform Document Identifier

➡ URL: Uniform Resource Locator

HTML: Hypertext Markup Language

HTTP: Hypertext Transfer Protocol

designed in 1989 by Tim Berners-Lee at the CERN

Info.cern.ch1st website on Christmas 1990

created on NeXT

Page 6: End-to-end HTML5 APIs - The Geek Gathering 2013

RESTRepresentational State Transfer

1. Null

2. Client-Server

3. Stateless

4. Cache

5. Uniform Interface

6. Layered System

7. Code on Demand: JavaScript

defined in 2000 by Roy Thomas Fielding in its dissertation

“Architectural Styles and the Design of Network-based Software Architectures”

http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htmhttp://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm

Page 7: End-to-end HTML5 APIs - The Geek Gathering 2013

Web Standards

Page 8: End-to-end HTML5 APIs - The Geek Gathering 2013

W3C

Created at the MIT in 1994

➡ Led by Tim Berners-Lee and Dr. Jeffrey Jaffe

Joint agreement among three "Host Institutions"

➡ MIT - ERCIM - Keio University

Working Groups

➡ HTML, MathML, RDF, SVG, CSS, Audio, Device...

Page 9: End-to-end HTML5 APIs - The Geek Gathering 2013

ECMAEuropean Computer Manufacturers Association

Standards: CD-ROM, ECMAScript, C#, Office Open XML File Formats

JavaScript

ECMA-262: ECMAScript (see also ISO/IEC 16262)

➡ TC39-TG1 managed by Mr. J. Neumann

➡ Test262

ECMA-357: E4X: ECMAScript for XML

ECMA-402: ECMAScript Internationalization API

ECMA-404: The JSON Data Interchange Format (was RFC 4627)

http://wiki.ecmascript.orghttp://www.ecma-international.org/publications/standards/Standard.htm

http://en.wikipedia.org/wiki/ECMAScript

Page 10: End-to-end HTML5 APIs - The Geek Gathering 2013

CommonJScreated in 2009 by Kevin Dangoor as ServerJS on Mozilla Wiki

➡ standards for JavaScript on the server

➡ Narwhal, Helma NG, v8CGI, GPSEE, chiron, Persevere, flusspferd

Renamed CommonJS

➡ command line tools, desktop, addon, or browser implementations

➡ joined by CouchDB, Wakanda, Sproutcore, node.js, RequireJS...

Modules, Packages, and Promises

Binary, FileSystem, System, I/O stream, Socket I/O

Browser like APIs: worker, console, HTTP client

https://wiki.mozilla.org/ServerJS http://www.commonjs.org/

Page 11: End-to-end HTML5 APIs - The Geek Gathering 2013

W3C on Server-Side ?

Really?

Page 12: End-to-end HTML5 APIs - The Geek Gathering 2013

DOM

Java

JavaScript

.NET

PHP

python

..;

Page 13: End-to-end HTML5 APIs - The Geek Gathering 2013

But also

XSL-FO

XSLT

XPath

XQuery

XML Schema

SOAP

WSDL

SVG

RDF

SPARQL

Page 14: End-to-end HTML5 APIs - The Geek Gathering 2013

Server-Side JavaScript

Page 15: End-to-end HTML5 APIs - The Geek Gathering 2013

Engines

Trident: MSHTML / Chakra-> Classic JScript, Managed JScript, & JScript.NET

TamarinJIT Compiler : NanoJIT

-> ActionScript / “ECMAScript 4”

CarakanLinear A, Linear B, Futhark

RhinoInterpreted or Compiled execution

webkit JavaScriptCore: JSCSquirrelFish Extreme: SFX aka Nitro

(JIT Compiler inside)

SpiderMonkey3 JIT Compilers: TraceMonkey, JägerMonkey, IonMonkey

V8JIT Compiler : CrankShaft

Page 16: End-to-end HTML5 APIs - The Geek Gathering 2013

Standards

• ECMAScript

• CommonJS

More than 60 SSJS implementations

Page 17: End-to-end HTML5 APIs - The Geek Gathering 2013

Servers

SpiderMonkey: GPSee, APE

Rhino: RingoJS, Persevere, AppJet, Glassfish

JavaScriptCore: wakanda

Trident / Chakra: IronJS, .NET

V8: node.js, SilkJS, TeaJS, Akshell

Page 18: End-to-end HTML5 APIs - The Geek Gathering 2013

NoSQL Databases

SpiderMonkey: riak, CouchDB

Rhino: OrientDB

JavaScriptCore: WakandaDB

V8: ArangoDB, MongoDB, CouchBase

Page 19: End-to-end HTML5 APIs - The Geek Gathering 2013

Web Application “1.0”

Page 20: End-to-end HTML5 APIs - The Geek Gathering 2013

HTML5 APIsXMLHttpRequest 2

Blob

File / FileSystem

Web SQL

Web Storage

Web Workers

Web Sockets

Web Cryptography

ImageData

Typed Arrays

Storage Quota

System Information

URL

WebCL

Page 21: End-to-end HTML5 APIs - The Geek Gathering 2013

WebCL

“This section proposes mechanisms for transferring pixel data between WebCL memory objects and HTML media elements. Server-side or Web Worker based implementations of WebCL will not be required to support these features.”

https://cvs.khronos.org/svn/repos/registry/trunk/public/webcl/spec/latest/index.html#4

Page 22: End-to-end HTML5 APIs - The Geek Gathering 2013

Web SQL

“This document was on the W3C Recommendation track but specification work has stopped. The specification reached an impasse: all interested implementors have used the same SQL backend (Sqlite), but we need multiple independent implementations to proceed along a standardisation path.”

http://www.w3.org/TR/webdatabase/

Page 23: End-to-end HTML5 APIs - The Geek Gathering 2013

Async “and” Sync

XMLHttpRequest(method, url, async)

FileReaderSync()

requestFileSystemSync()

openDatabaseSync()

indexedDBSync.open()

localStorage.getItem()

Page 24: End-to-end HTML5 APIs - The Geek Gathering 2013

IndexedDB

“The synchronous database API methods provide a blocking access pattern to IndexedDB databases. Since they block the calling thread they are only available from workers.”

http://www.w3.org/TR/IndexedDB/#sync-database

Page 25: End-to-end HTML5 APIs - The Geek Gathering 2013

Web WorkersDedicated or Shared

No Window, No Document

WorkerGlobal, WorkerUtils, WorkerNavigator, WorkerLocation

postMessage(), onmessage(), onerror()

importScripts()

Page 26: End-to-end HTML5 APIs - The Geek Gathering 2013

Concept

Server JS contexts

==

JS Workers

➡ multi-threaded Dedicated Workers

➡ Shared Worker EventLoop

Page 27: End-to-end HTML5 APIs - The Geek Gathering 2013

Remote Debugging

Page 28: End-to-end HTML5 APIs - The Geek Gathering 2013

Protocols

Firebug Crossfire

Crossfire for Internet Explorer

V8 Debugger Protocol

Opera Scope Protocol

Webkit “Remote Debugging Protocol 1.0”

Mozilla Debugging Protocol

Page 29: End-to-end HTML5 APIs - The Geek Gathering 2013

Purpose

Original

➡ Debug JS code running in mobiles

Implicit

➡ Debug JS code running on servers

Page 30: End-to-end HTML5 APIs - The Geek Gathering 2013

Concept

Server JS contexts

===

Remote JS Workers

Page 31: End-to-end HTML5 APIs - The Geek Gathering 2013

Present & Future

Page 32: End-to-end HTML5 APIs - The Geek Gathering 2013

caniuse “SS-HTML5”node.js wakanda RingoJS SilkJS APE

Timers YES YES

Base64 module module module module

XHR module YES ? YES YES

Blob YES ? ?

Storage YES* ? ?

Workers module YES** YES ?

Sockets module WAK7 ? ?

FileSystem YES ? ?

SSE module module

DOM module ? ?

SQL module

WebCL modulehttp://www.w3.org/community/jseverywhere/wiki/Main_Page

Page 33: End-to-end HTML5 APIs - The Geek Gathering 2013

RingoJSHTML5

➡Web Worker

CommonJS

➡Modules

➡ System, fs, binary, IO, Unit Test

Other

➡ console

Page 34: End-to-end HTML5 APIs - The Geek Gathering 2013

node.jsHTML5 via modules

➡ XMLHttpRequest (node-xmlhttprequest)

➡ Web Sockets (node-websocket-client)

➡ DOM (jsdom),

➡ IndexedDB (perstore), Web SQL (node-sqlite)

CommonJS

➡ Modules*, Packages

Other: console*

Page 35: End-to-end HTML5 APIs - The Geek Gathering 2013

Wakanda

HTML5

➡ XMLHttpRequest, WindowTimer,

➡ Web Storages*

➡ Web Workers**

➡ File, FileSystem, Blob, ...

CommonJS

➡ Modules, Packages, System, Unit Test

Other: console

Page 36: End-to-end HTML5 APIs - The Geek Gathering 2013

Wakanda

* Web Storages

➡ sessionStorage, “user.storage”, “application.storage”

➡ lock(), tryLock(), unlock()

➡ no localStorage but easy to polyfil

➡ “storage” event planned

** Web Workers

➡ Worker, SharedWorker, “SystemWorker”

Page 37: End-to-end HTML5 APIs - The Geek Gathering 2013

Wakanda

Server-side JS context

➡ CommonJS (module.id, require, ...)

➡ Worker (importScripts, WindowTimer, ...)

Page 38: End-to-end HTML5 APIs - The Geek Gathering 2013

CommonNodeHTML5 via modules

➡ XMLHttpRequest (node-xmlhttprequest)

➡ Web Sockets (node-websocket-client)

➡ DOM (jsdom)

➡ IndexedDB (perstore), Web SQL (node-sqlite)

CommonJS

➡ Modules, Packages

➡ System, fs, binary, IO, Unit Test

Other: console

http://olegp.github.io/common-node/

Page 39: End-to-end HTML5 APIs - The Geek Gathering 2013

SummaryECMAScript is already everywhere

Modules

➡ CommonJS already standard

➡ AMD (Asynchronous Module Definition)

➡ ECMAScript 6

Many W3C APIs already applicable server-side

Same APIs means

➡ better learning curve

➡ more shared libraries / modules

➡ DRY -> shared Model work Offline

Page 40: End-to-end HTML5 APIs - The Geek Gathering 2013

Client and Server JavaScript APIs W3C Community Group

http://www.w3.org/community/jseverywhere/

Let’s start!

Page 41: End-to-end HTML5 APIs - The Geek Gathering 2013

Q & A

San Francisco, CA - Oct. 25th

http://jseverywhere.org

Wakanda

http://wakanda.org

@jseverywhere

@wakandasoft

Client and Server JavaScript APIs Community Group

http://www.w3.org/community/jseverywhere/