Slide 1

Slide 1 text

Why Mobile Web Still Sucks? Ilya Pukhalski May MMXIV

Slide 2

Slide 2 text

@pukhalski ! Solution Architect, EPAM Systems Lecturer, British Higher School of Art & Design

Slide 3

Slide 3 text

% of time spent 2013 2014 14 20 86 80 Apps Mobile Web

Slide 4

Slide 4 text

Why apps? • Easy to control over stores • Rich-get-richer dynamics • Easier to retain users

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

HTML5 vs Native on mobile Web

Slide 8

Slide 8 text

Watch your language • HTML5 is a marketing buzzword • Responsive Web Design doesn’t exist Good design is responsive by default.

Slide 9

Slide 9 text

What is web?

Slide 10

Slide 10 text

– Wiki “Web is a system of interlinked “hypertext documents that run “on and are accessed “via the Internet.”

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Custom URL schemas • fb://profile/(fbid) • tel:+180022933 • twitter://username • …

Slide 13

Slide 13 text

applinks.org

Slide 14

Slide 14 text

Native is a part of Web ecosystem

Slide 15

Slide 15 text

What is native?

Slide 16

Slide 16 text

“Native — software or data “formats supported by a certain “system with minimal overhead “and additional components” – Wiki

Slide 17

Slide 17 text

Web technologies are native for browsers

Slide 18

Slide 18 text

Browsers are responsible for standards support

Slide 19

Slide 19 text

Apps boom Do you remember dot-com boom?

Slide 20

Slide 20 text

Why do we love apps? • Push Notifications • Offline Mode • Performance ! ! • Look & Feel • Distribution • Background Sync

Slide 21

Slide 21 text

Look & Feel

Slide 22

Slide 22 text

famo.us

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Touch Events, Pointer Events, Mouse Events

Slide 25

Slide 25 text

~300ms delay

Slide 26

Slide 26 text

tap.js

Slide 27

Slide 27 text

document .getElementById('any-element') .addEventListener('tap', function (e) { // All the magic happens here }); $('#any-element').on('tap', function (e) { // All the magic happens here });

Slide 28

Slide 28 text

Performance

Slide 29

Slide 29 text

Heavy DOM

Slide 30

Slide 30 text

Facebook React.js Model DOM Virtual DOM Redraw on requestAnimationFrame Changes Changes Changes

Slide 31

Slide 31 text

Animations

Slide 32

Slide 32 text

2010-2013

Slide 33

Slide 33 text

2014

Slide 34

Slide 34 text

requestAnimationFrame

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

element.animate([ {cssProperty: value0}, {cssProperty: value1}, {cssProperty: value2}, //... ], { duration: timeInMs, iterations: iterationCount, delay: delayValue });

Slide 38

Slide 38 text

Offline Mode

Slide 39

Slide 39 text

Cache Manifest

Slide 40

Slide 40 text

A declarative way CACHE MANIFEST # 2012-02-21 v1.0.0 /theme.css /logo.png /main.js ! NETWORK: login.asp ! FALLBACK: /html/ /offline.html

Slide 41

Slide 41 text

A mess CACHE MANIFEST # v1 index.html js/lib/mapbox.js js/lib/iscroll.min.js js/lib/jquery/dist/jquery.min.js js/lib/backbone/backbone.min.js js/lib/underscore/underscore.min.js js/xf.min.js js/app.js styles/xf.min.css styles/app.css styles/mapbox.css js/components/PointsList.js tmpl/desktop/PointsList.tmpl tmpl/mobile/PointsList.tmpl js/components/PointsMap.js https://api.tiles.mapbox.com/mapbox.js/v1.6.1/images/icons-000000.png http://api.tiles.mapbox.com/mapbox.js/v1.6.1/images/icons-000001.png http://api.tiles.mapbox.com/mapbox.js/v1.6.1/images/icons-000002.png http://api.tiles.mapbox.com/mapbox.js/v1.6.1/images/icons-000003.png http://api.tiles.mapbox.com/mapbox.js/v1.6.1/images/icons-000004.png http://api.tiles.mapbox.com/mapbox.js/v1.6.1/images/icons-000005.png http://a.tiles.mapbox.com/v3/witchfinderx.hb934388.json http://a.tiles.mapbox.com/v3/marker/pin-s-fuel+fc4353.png http://a.tiles.mapbox.com/v3/marker/pin-m-circle+f0a.png NETWORK: http://api.tomtom.com/ http://a.tiles.mapbox.com/ http://b.tiles.mapbox.com/ http://c.tiles.mapbox.com/

Slide 42

Slide 42 text

Debugging hell 1. Change the code 2. Change manifest 3. Clean cache 4. Debug 5. GOTO 1

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Meet Service Worker

Slide 45

Slide 45 text

Event-driven scripts that run independently of web pages

Slide 46

Slide 46 text

• Handling resource requests • Foundation for other standards

Slide 47

Slide 47 text

navigator.serviceWorker.register('/worker.js') .then(function(serviceWorker) { // To use the serviceWorker immediately, // you might call window.location.reload() });

Slide 48

Slide 48 text

var base = "https://videos.example.com"; var inventory = new URL("/inventory.json", base) + ""; ! ! this.addEventListener("fetch", function(e) { var url = e.request.url; if (url == inventory) { e.respondWith(new Response({ statusCode: 200, body: JSON.stringify({ videos: { /* ... */ } }) })); } });

Slide 49

Slide 49 text

var base = "https://videos.example.com"; ! this.addEventListener("install", function(e) { ! var cachedResources = new Cache( base + "/base.css", base + "/app.js", base + "/logo.png" ); ! ! e.waitUntil(cachedResources.ready()); ! ! caches.set("videos-cache", cachedResources); });

Slide 50

Slide 50 text

this.addEventListener("fetch", function(e) { ! e.respondWith( caches.match(e.request, “videos-cache") ); });

Slide 51

Slide 51 text

var base = "https://videos.example.com"; var inventory = new URL("/inventory.json", base)+""; ! this.addEventListener("fetch", function(e) { var url = e.request.url; if (url == inventory) { e.respondWith( fetch(url).then( null, function() { return caches.match(inventory); } ) ); } });

Slide 52

Slide 52 text

Distribution

Slide 53

Slide 53 text

Stores • App Store • Google Play • BlackBerry AppWorld • Amazon Appstore • EPAM Mobile Appstore

Slide 54

Slide 54 text

Stores • App Store • Google Play • BlackBerry AppWorld • Amazon Appstore • EPAM Mobile Appstore

Slide 55

Slide 55 text

Will you install an app to buy a car?

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Install this app

Slide 60

Slide 60 text

navigator .mozApps .install("path/to/manifest");

Slide 61

Slide 61 text

Notifications

Slide 62

Slide 62 text

Web Notifications

Slide 63

Slide 63 text

var Notification = window.Notification || window.mozNotification || window.webkitNotification; ! Notification.requestPermission( function (permission) { // console.log(permission); } );

Slide 64

Slide 64 text

! var notification = new Notification( "SEC Spring 2014", { body: "I hope you enjoy the conference" } ); ! notification.onclick = function () { // Something to do };

Slide 65

Slide 65 text

• Opened website • Client-side only

Slide 66

Slide 66 text

Safari Remote Notifications

Slide 67

Slide 67 text

The Flow • Request permissions • Register the device • Send notifications

Slide 68

Slide 68 text

{! ! "aps": {! ! "alert": {! ! "title": "Flight A998 Now Boarding",! ! "body": "Boarding has begun for Flight A998.",! ! "action": "View"! ! },! ! "url-args": ["boarding", "A998"]! ! }! ! }!

Slide 69

Slide 69 text

• Server-side • Offline

Slide 70

Slide 70 text

Service Worker Push Notifications

Slide 71

Slide 71 text

The Flow • Register locally • Register on the server side • Send notifications

Slide 72

Slide 72 text

navigator.serviceWorker.register("/sw.js"); ! navigator.serviceWorker.whenReady().then(function(sw) { ! navigator.push.has("regId").catch(function() { navigator.push.register({ sender: { // sender data... } }); }).then(function (registration) { asyncXHR( "http://example.com/push/activate" + toQueryString(registration); ); }); });

Slide 73

Slide 73 text

this.onpush = function(e) { console.log(e.message.data); // Cache the data // ... }

Slide 74

Slide 74 text

Background Sync

Slide 75

Slide 75 text

Service Worker? Yes!

Slide 76

Slide 76 text

navigator.serviceWorker.register("/sw.js"); ! ! navigator.serviceWorker.whenReady() .then(function(sw) { ! navigator.registerSync( "id", { interval: 'daily', data: '', description: '', lang: '', dir: '' } ); });

Slide 77

Slide 77 text

this.onsync = function(event) { var data = JSON.parse(event.data); ! if (event.id === "id") { // make something with data } };

Slide 78

Slide 78 text

How to make mobile web suck less?

Slide 79

Slide 79 text

Blame the implementation, not technique

Slide 80

Slide 80 text

Thanks @pukhalski [email protected]