45
Building Responsive Web Applications with MVC4, WebAPI and HTML5 Brendan Kowitz Senior Developer DEV332

Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Embed Size (px)

Citation preview

Page 1: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Building Responsive Web Applications with MVC4, WebAPI and HTML5Brendan KowitzSenior Developer

DEV332

Page 2: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Who am I?

[email protected]

http://www.kowitz.net

@brendankowitz

Page 3: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Overview

Going offline

Packaging

Data + WebAPI

Building a great user experience

Page 4: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Build for a wide audience

MVC4

Multi BrowserMulti PlatformMulti Form factorMulti Screen Resolutions

Page 5: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Why responsive mobile web applications

Responsive, fluid usage, respond to online and offline events

Interact with device hardware* and storage to create a personalised experience

Build and package for app stores / market places, in place of native apps

Page 6: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Responding to mobile growth

Own a smartphone

20112012

Mobile web access

20102012

http://tinyurl.com/9bcyq86

44%

59%

26%

58%

http://www.itu.int/ITU-D/ict/statistics/at_glance/KeyTelecom.html

Page 7: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Why responsive web applicationsBest of desktop smart-client apps

Combined with the very latest and best of the web

Great for enhancing the user experience of web applications

Page 8: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Responsive options

Do nothingJust add the meta viewport tag:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Page 9: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Responsive options

Adaptive Layout• CSS3 Media queries

Page 10: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Responsive options

Adaptive Rendering

Page 11: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Responsive options

Responsive client-side apps

Page 12: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Mini Quizvar myArray = new Array();

myArray["first"] = "Hello";myArray["second"] = "World";

alert(myArray.length);

02nullundefinedthrow

Page 13: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

JavaScript applicationsHow can we write better JavaScript?

Page 14: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Common client-side patterns

http://xkcd.com/292/

Page 15: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Common client-side patterns

Module PatternNamespaces (MS Ajax Toolkit)MVC (Spinejs, Backbonejs, JavaScript MVC)MVVM (Knockout, WinJS)

Page 16: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

MVVM

View

ViewModel

Model

Page 17: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Knockout<p>First name: <strong data-bind="text: firstName"></strong></p><p>Last name: <strong data-bind="text: lastName"></strong></p>

function AppViewModel() {    this.firstName = ko.observable("Bert");    this.lastName = ko.observable("Bertington");}

ko.applyBindings(new AppViewModel());

Page 18: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Responsive UI toolkitsjQuery UI + jQueryMobileTelerik’s Kendo UI + MobileTwitter bootstrap

iOS Android WP7 DesktopJQueryUI / Mobile Excellent Good Functional ExcellentKendo Excellent Excellent Not Supported ExcellentBootstrap Good Good Good Excellent

Page 19: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

HTML formsUse browser and device native features whenever possibleInput types: eg. number, email, url, date should be usedUse Polyfills to broaden compatibilityhttps://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

Page 20: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Traditional apps

Browser Request

Index.html

MVC4

Traditional Request / Response for ALL rendered content and assets

Page 21: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Structuring responsive appsInitial Request

Application.htm

MVC4

RequireJS Loader

Page1 Partial.htm

IndexViewModel.js

Application.js (bootstrap)

ViewModel (#index)

ViewModel (#login)

Model (LoginModel)JSON Requests

HTML5 localstorage

Handling disconnection

Page 22: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Application compositionUsing libraries in your page

CommonJS specificationRequireJS (Modules/AsynchronousDefinition)Node.js (Modules/1.0)

Script Loaders (load scripts in parallel)YepNope YabbleLABjs

http://www.commonjs.org/

Page 23: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

introducing…

Tiny Contact Manager

Page 24: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Screen shots

Page 25: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

demo Building a responsive UI

Page 26: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

MVC4 WebAPIGreat for building convention based REST APIsGreat support for JSON, XML data types

Page 27: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

demo

WebAPI

Page 28: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Working with AsyncPromise Pattern

$.ajax("http://www.example.org/somedata.json”)  .then(myFunc, myFailure);

jQuery 1.5+

Page 29: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Working with AsyncPromise Pattern

WinJS.xhr({ url:"http://www.example.org/somedata.json"}).then(function (response) { updateDisplay(JSON.parse(response.responseText));});

WinJS

Page 30: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Cache manifestCACHE MANIFEST## Version: 1.0

CACHE:/m/Content/background.png/m/index.htm/m/scripts/require.js/m/scripts/main-built.js

NETWORK:*

Page 31: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Cache manifestLeverage MVC4 to programmatically build this

Page 32: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

demo

Cache manifest

Page 33: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Using LocalstorageUnder the HTML5 group of technologiesAccess can vary based on privacy settings on the deviceLimited StorageAvailable in PhoneGap*

(after device ready event)

Page 34: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

RecapWhy we need responsive appsClient-side patternsUI ToolkitsHTML5 FormsWebAPICache Manifest

Page 35: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Bundling and minificationSystem.web.optimisationsNode.js tools:

Require.js optimiserStackservice Bundler:

Page 36: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Node.js

If you don’t have it,It’s time to go download it.

http://nodejs.org/

Page 37: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Require.jsr.js is the Require.js optimiser

npm install requirejs -gnode r.js -o scripts/app.build.js

Page 38: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

demo

Require.js

Page 39: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Wrap up

Going offline

Packaging

Data + WebAPI

Building a great user experience üüüü

Page 40: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Further reading

Page 42: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Think aboutWhat’s one pattern you can use to help develop responsive apps?

What’s one feature in ASP.NET MVC4 that helps with responsive apps?

Would you consider writing a responsive app for your next project?

Page 44: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

Related ContentAZRILL102 Exploring Windows Azure Storage

Modern App Development: Demo Pod 2

MCPD: Web Developer 4

Find Me Next up at the Speaker Lounge

Page 45: Building Responsive Web Applications with MVC4, …seach9.blob.core.windows.net/teched/2012/aus/DEV332_… · PPT file · Web viewBuilding Responsive Web Applications with MVC4,

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS

PRESENTATION.