html5 programming

39
HTML5 Programming Nam Ho KMS Technology

Upload: hotrannam

Post on 16-May-2015

1.022 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: HTML5 Programming

HTML5 ProgrammingNam Ho

KMS Technology

Page 2: HTML5 Programming

HTML5 won’t be ready until 2022!

Page 3: HTML5 Programming

Do I need to wait for the specifications are complete?

Page 4: HTML5 Programming

Real-world browser support is what matters!

Page 5: HTML5 Programming

A desktop example

http://www.pirateslovedaisies.com/

Page 6: HTML5 Programming

A mobile example

http://m.microsoft.com/windowsphone/en-us/demo/index.html

Page 7: HTML5 Programming

The current state of HTML5 support

http://caniuse.com/

Page 8: HTML5 Programming
Page 9: HTML5 Programming

Why programming?

Page 10: HTML5 Programming

This presentation doesn’t cover

• Semantics & Markups• HTML5 Forms• Web Workers• WebGL• CSS3• SVG• …

Page 11: HTML5 Programming

This presentation covers

• Video• Canvas• WebSocket• Data Storage • Offline• FileSystem• Geolocation

Page 12: HTML5 Programming

Multimedia

These specifications defines the video/audio elements with all the available methods, attributes and events. Through the new APIs you can access, control and manipulate timeline data and network states of the files. With the coming additions to the APIs you will be able to read and write raw data to audio files (Audio Data API) or manipulate captions in videos (Timed Track API).

Page 13: HTML5 Programming

Video

• Native video• Video tag

– <video src=“light.ogv” controls autoplay />

• Formats– .mp4 = H.264 + AAC– .ogg/.ogv = Theora + Vorbis– .webm = VP8 + Vorbis

• Legacy browser fallback

Page 14: HTML5 Programming

Audio

• Native audio• Audio tag

– <audio src=“hello.ogg” controls />

• Formats– .ogg/.oga– .mp3– .wav– .aac (Advanced Audio Coding)

• Legacy browser fallback

Page 15: HTML5 Programming

MIME types

Format Attribute type MIME type

.ogg video/ogg application/ogg

.mp4 video/mp4 video/mpeg

.webm video/webm video/webm

.mp3 audio/mp3 audio/mpeg

.wav audio/wav audio/wav

.aac audio/aac audio/aac

.mp4 audio/mp4 audio/mp4

Page 16: HTML5 Programming

Canvas

The canvas element provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, or other visual images on the fly.

Page 17: HTML5 Programming

Canvas

• Native drawing surface• Canvas tag

– <canvas id=“square” width=“10” height=“10” />

• JavaScript API for 2D drawing

Page 18: HTML5 Programming

WebSocket

To enable Web applications to maintain bidirectional communications with server-side processes, this specification introduces the WebSocket interface.

Page 19: HTML5 Programming

WebSocket

• WebSocket object• New protocol

– ws://html5rocks.websocket.org/echo

• Establishing an open connection– Client and server can send data at any time– Realtime web application

Page 20: HTML5 Programming

WebSocket example

Page 21: HTML5 Programming

Web Storage

This specification introduces two related mechanisms, similar to HTTP session cookies, for storing structured data on the client side.

Page 22: HTML5 Programming

Web storage

• Avoiding HTTP overhead of cookies• Key-value pairs• Local storage• Session storage• Quota– Needing user confirmation if exceeding storage

capability

Page 23: HTML5 Programming

Indexed Database

This specification defines APIs for a database of records holding simple values and hierarchical objects. Each record consists of a key and some value. Moreover, the database maintains indexes over records it stores. An application developer directly uses an API to locate records either by their key or by using an index. A query language can be layered on this API. An indexed database can be implemented using a persistent B-tree data structure.

Page 24: HTML5 Programming

Indexed database

• Object based data store• Asynchronous API• Execute commands and open cursor inside

transactions

Page 25: HTML5 Programming

Opening indexed database

Page 26: HTML5 Programming

Creating an Object Store

Page 27: HTML5 Programming

Storing data into Object Store

Page 28: HTML5 Programming

Querying data by cursor

Page 29: HTML5 Programming

Offline

In order to enable users to continue interacting with Web applications and documents even when their network connection is unavailable — for instance, because they are traveling outside of their ISP's coverage area — authors can provide a manifest which lists the files that are needed for the Web application to work offline and which causes the user's browser to keep a copy of the files for use offline.

Page 30: HTML5 Programming

Application cache

• Cache resources locally– HTML, CSS, JavaScript, images, etc.

• Use a manifest file to specify resources in order to cache• Download caching resources in a transaction• window.applicationCache• Add manifest attribute to html tag

– manifest=“example.appcache”• MIME type

– text/cache-manifest appcache• Clear cache: chrome://appcache-internals/

Page 31: HTML5 Programming

Manifest fileCACHE MANIFEST#v1.0.0

CACHEindex.htmlstyle.cssScripts/main.jsimages/logo.png

FALLBACKtime.js fallback_time.js

Page 32: HTML5 Programming

Updating to new version

Page 33: HTML5 Programming

FileSystem

This specification defines an API to navigate file system hierarchies, and defines a means by which a browser may expose sandboxed sections of a user's local file system to web applications.

Page 34: HTML5 Programming

File system

• Sandboxed environment• Allow create/edit/delete files and directories

Page 35: HTML5 Programming

Geolocation

The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. The API itself is agnostic of the underlying location information sources. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input. No guarantee is given that the API returns the device's actual location.

Page 36: HTML5 Programming

Geolocation• Allow users to share their location for location-aware services

– Application >> Browser >> 3rd services such as Skyhook or Google

• Privacy– Users are asked to share their location

• navigator.geolocation– getCurrentPosition– watchPosition

• Location metadata– latitude/longtitude/altitude– accuracy/altitudeAccuracy– heading/speed

Page 37: HTML5 Programming

Resources

• HTML5 rocks– http://www.html5rocks.com/en/

• Modernizr– http://www.modernizr.com/

• Mobile HTML5– http://mobilehtml5.org/

• Source code– http://bit.ly/tZ6eBn

Page 38: HTML5 Programming

Q & A

Email: [email protected]: @hotrannam

Page 39: HTML5 Programming

Thank you for joining!