develop high performance windows 8 application with html5 and javascripthigh perfw8appdevv1

65

Upload: doris-chen

Post on 12-May-2015

7.807 views

Category:

Technology


0 download

DESCRIPTION

Creating high performance apps is crucial for every developer. Come to learn How to make your HTML5 apps fast and responsive on Windows 8 platform. In this session, first we will start with the overview of Windows 8 and then introduce how to develop Windows 8 using HTML5 and JavaScript. We will explore the best practices and performance tricks to make your Windows 8 applications running faster.

TRANSCRIPT

Page 1: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 2: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #wins8camp http://bit.ly/wins8cheatsheet Blog http://blogs.msdn.com/dorischen

Who am I? Developer Evangelist at Microsoft based in Silicon Valley, CA

Blog: http://blogs.msdn.com/b/dorischen/

Twitter @doristchen

Email: [email protected]

Office Hours http://ohours.org/dorischen

Has over 15 years of experience in the software industry focusing on web technologies

Spoke and published widely at JavaOne, O'Reilly, Silicon Valley Code Camp, SD West, SD Forum and worldwide User Groups meetings

Doris received her Ph.D. from the University of California at Los Angeles (UCLA)

PAGE 2

Page 3: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 4: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

As of March 2012, IDC

Page 5: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 6: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 9

Page 7: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

HTML App Platform

App container

HTML host process

Internet Explorer

Web

platform

TAB

App code

Web platform

Windows

runtime

App code

Page 8: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 9: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 10: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE

14

Page 11: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 15

Page 12: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 16

Page 13: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 14: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 23

Page 15: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 24

Page 16: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 17: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

The development tools are FREE!

If you use a higher SKU, it just works!

Page 18: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 19: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE

29

Page 20: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

demo

Page 21: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

http://blogs.msdn.com/b/dorischen/archive/2012/10/02/transform-your-html-css-javascript-apps-into-windows-8-application.aspx

http://github.com/appendto/jquery-win8

interoperability@Microsoft blog

http://msdn.microsoft.com/en-us/library/windows/apps/hh700404.aspx

Page 22: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE

35

Page 23: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 24: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

"Code for touch, get mouse and pen for free!"

Page 25: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 26: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

function onLoad() {

...

var workSpaces = document.getElementsByClassName("workspace");

for (i = 0; i < workSpaces.length; i++) {

workSpaces[i].addEventListener("MSPointerDown", pointerDownHandler, false);

workSpaces[i].addEventListener("MSPointerMove", pointerMoveHandler, false);

workSpaces[i].addEventListener("MSPointerUp", pointerUpHandler, false);

workSpaces[i].addEventListener("MSManipulationStateChanged",

resetInteractions, false);

}

...

}

Page 27: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 28: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Tips & tricks that still work

http://channel9.msdn.com/Events/Build/2012/3-132

Page 29: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

function InsertUsername()

{

document.getElementById('user').innerHTML = userName;

}

User innerHTML to Create your DOMUse DOM Efficiently

Page 30: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

<html>

<head>

<script type="text/javascript">function helloWorld() {

alert('Hello World!') ;}

</script>

</head>

<body>

</body>

</html>

Avoid Inline JavaScriptEfficiently Structure Markup

Page 31: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

JSON Always Faster than XML for Data

JSON Representation"glossary":{

"title": "example glossary", "GlossDiv":{

"title": "S", "GlossList": {

"GlossEntry": {

"ID": "SGML",

"SortAs": "SGML",

"GlossTerm": "Markup Language",

"Acronym": "SGML",

"Abbrev": "ISO 8879:1986",

"GlossDef": {

"para": "meta-markup language",

"GlossSeeAlso": ["GML", "XML"] },

"GlossSee": "markup" }

}

}

}

XML Representation<!DOCTYPE glossary PUBLIC "DocBook V3.1">

<glossary><title>example glossary</title>

<GlossDiv><title>S</title>

<GlossList>

<GlossEntry ID="SGML" SortAs="SGML">

<GlossTerm>Markup Language</GlossTerm>

<Acronym>SGML</Acronym>

<Abbrev>ISO 8879:1986</Abbrev>

<GlossDef>

<para>meta-markup language</para>

<GlossSeeAlso OtherTerm="GML">

<GlossSeeAlso OtherTerm="XML">

</GlossDef>

<GlossSee OtherTerm="markup">

</GlossEntry>

</GlossList>

</GlossDiv>

</glossary>

Page 32: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Native JSON Methods

var jsObjStringParsed = JSON.parse(jsObjString);

var jsObjStringBack = JSON.stringify(jsObjStringParsed);

Use Native JSON MethodsWrite Fast JavaScript

Page 33: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 34: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 35: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Loading and

parsing

of

HTML, JS, CSS

New host

process

Tile click

"DOMContentLoaded" event

Windows Runtime

"activated" event

Splash screen

Ready for

user

Navigation

App visible

Page 36: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Optimize your landing page: Package Locally

Page 37: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Optimize your landing Page: Use Local Data

Page 38: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Internet Internet

5

Fetch Info

From Network

Cache Info

LocallyFetch Info

From Cache

No Network

Available

AppCache

Page 39: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Internet Internet

HTML 5 AppCache – Update Flow

Fetch Manifest

From Network

If diff Create New

CacheFetch Info

From CacheNo Network

Available

AppCache

Page 40: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #devcamp lab setup: http://bit.ly/html5setup Blog http://blogs.msdn.com/dorischen

manifest file

PAGE 60

Page 41: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

MIME Type: text/cache-manifest

Page 42: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #devcamp lab setup: http://bit.ly/html5setup Blog http://blogs.msdn.com/dorischen PAGE 62

Page 43: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #devcamp lab setup: http://bit.ly/html5setup Blog http://blogs.msdn.com/dorischen

var oRequestDB = window.indexedDB.open(“Library”);

oRequestDB.onsuccess = function (event) {

db1 = oRequestDB.result;

if (db1.version == 1) {

txn =db1.transaction([“Books”],IDBTransaction.READ_ONLY);

var objStoreReq = txn.objectStore(“Books”);

var request = objStoreReq.get("Book0");

request.onsuccess = processGet;

}

};

Page 44: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Optimize landing page: Load only what you need

<script type="text/javascript" src='file1.js'defer='defer'></script>

Page 45: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Further optimizations

Page 46: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Be lightweight, control your Resource Usage

Page 47: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

App gets 5s to handle

suspend

App is not notified

before termination

Apps are notified when

they have been resumed

User

Launches

App

Splash

screen

Page 48: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Manage your resources

URL.revokeObjectURL

var url = URL.createObjectURL(blob, {oneTimeOnly: true});

Page 49: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

// Pick an image filepicker.pickSingleFileAsync()

.then(function (file) {var properties = Windows.Storage.FileProperties.ThumbnailMode;return file.getThumbnailAsync(properties.singleItem, 1024);

}).then(function (thumb) {

var imgTag = document.getElementById("imageTag");imgTag.src = URL.createObjectURL(thumb, false);

});

// Pick an image filepicker.pickSingleFileAsync()

.then(function (file) {var imgTag = document.getElementById("imageTag");imgTag.src = URL.createObjectURL(file, false);

});

Manage your Resources:

// Open File Picker

var picker = new Windows.Storage.Pickers.FileOpenPicker();

picker.fileTypeFilter.replaceAll([".jpg", ".png"]);

Page 50: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Show you’re listening, process user inputs

Page 51: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

0s 1s 2s 3s

UI thread

Launch User input Animation

Page 52: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #devcamp lab setup: http://bit.ly/html5setup Blog http://blogs.msdn.com/dorischen

Typical Execution Flow on the UI thread

JavaScript

Web Worker

JavaScript

LayoutUpdate View

User Input Event,

Timer,

or Callback

UI Thread

Update App

Logic

Page 53: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #devcamp lab setup: http://bit.ly/html5setup Blog http://blogs.msdn.com/dorischen

Page 54: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

twitter #devcamp lab setup: http://bit.ly/html5setup Blog http://blogs.msdn.com/dorischen PAGE 75

Page 55: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

xhr//access a web service, cloud service, local resource

http://www.example.org/somedata.json

Page 56: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

Activation time Memory leaks

UI responsiveness Idle state CPU usage

Layout passes Successful suspend

Synchronous XMLHttpRequest on UI

thread

Memory reduction when suspended

Image scaling App memory growth

Memory footprint Runtime broker memory growth

Runtime broker memory reference set

Page 57: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 58: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 79

Page 59: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE 80

Page 60: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 61: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 62: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1
Page 63: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

http://bit.ly/2000Cash

Publish your app to the Windows Store and/or Windows Phone Store March 8, 2013 through June 30, 2013

Submit up to 10 published apps per Store and get a $100 Virtual Visa®

More: http://bit.ly/2000Cash

Page 64: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

http://bit.ly/HTML5Wins8Camp

http://bit.ly/CampInBox

http://msdn.microsoft.com/en-us/library/windows/apps/hh465194.aspx

http://Aka.ms/brockschmidtbook

http:/dev.windows.comPAGE

86

Page 65: Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh perfw8appdevv1

PAGE

87

• Responsive Web Design and CSS3

• http://bit.ly/CSS3Intro

• HTML5, CSS3 Free 1 Day Training

• http://bit.ly/HTML5DevCampDownload

• Using Blend to Design HTML5 Windows 8 Application (Part II): Style,

Layout and Grid

• http://bit.ly/HTML5onBlend2

• Using Blend to Design HTML5 Windows 8 Application (Part III): Style

Game Board, Cards, Support Different Device, View States

• http://bit.ly/HTML5onBlend3

• Feature-specific demos • http://ie.microsoft.com/testdrive/

• Real-world demos• http://www.beautyoftheweb.com/