Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
Taming the browsers of tomorrow - Flurin Egger
26:16 with Flurin EggerModern browsers are advanced pieces of software, and have been evolving at lightning speed ever since we've left IE6 in the dirt and moved on to FireFox and Chrome. But what's new today will be old tomorrow, and not everything that is new is necessarily better. Nevertheless, it's very exciting to see the common browser slowly break out of it's boundaries to evolve into an OS. In this talk we'll have a look at the API's that future versions of browsers will bring us, and what we would be able to do with them. Some of these API's we'll analyse in depth to see what their real life application would look like. And while we're exploring these cutting edge technologies, we will also reflect on what they will mean for the web and for us as web developers.
-
0:00
[Taming the Browsers of Tomorrow] [Flurin Egger]
-
0:02
[Sideview 2013] [Sponsored by Treehouse]
-
0:05
[Flurin Egger] [Digitpaint]
-
0:08
Thank you.
-
0:10
Taming the Browsers of Tomorrow.
-
0:13
My name is Flurin.
-
0:15
There's a picture of me back when I was really cool.
-
0:19
Nowadays I just work a lot.
-
0:23
I work at a small company in the Netherlands called Digitpaint,
-
0:26
and we do mostly front-end work,
-
0:28
and my job is to actually get people together to work on front end,
-
0:37
and I'm also the guy that gets to experiment with new stuff.
-
0:42
So I'm going to talk about things in browsers and APIs,
-
0:50
and big things are happening to browsers,
-
0:54
especially this year.
-
0:56
There's really a lot going on,
-
0:59
and the browsers, they are getting smarter
-
1:04
and more aware of their surroundings,
-
1:08
and actually 7 years ago you had no input,
-
1:15
like video, audio, or touch input wasn't really there.
-
1:25
So this talk will be about APIs,
-
1:30
but I'm not going to talk about the big stuff.
-
1:33
As I said, 2013 was really great,
-
1:37
but I'm not going to talk about the Shadow DOM today,
-
1:40
because that has been covered a lot.
-
1:42
There are a lot of blog posts around that.
-
1:45
There are a lot of talks this year about Shadow DOM.
-
1:48
I'm also not going to talk about WebGL.
-
1:51
It's really awesome, but not today.
-
1:54
I'm also not going to talk about WebRTC.
-
1:56
Also, these technologies are awesome, and they're cool,
-
2:00
but I'm going to talk about 6 pieces of small magic.
-
2:07
I think a lot of this is underappreciated.
-
2:12
As I said, you talk a lot about the big stuff,
-
2:20
but this is the small stuff I'm going to talk about.
-
2:22
And the first thing I'm going to cover is not an API.
-
2:26
It's promises, or it used to be called futures,
-
2:31
and I'm going to talk about native promises.
-
2:35
You've probably heard about them.
-
2:43
If you have not, this is what the promise is.
-
2:47
A promise represents the eventual result of an asynchronous operation just like a marriage.
-
2:57
But what does this mean? What does this solve?
-
3:00
Because if you say we have events for this—
-
3:04
but the thing is there are 2 key words in the sentence, eventual and asynchronous.
-
3:08
I'm going to give a short demonstration with this scenario.
-
3:14
Let's say we have to fetch a list of news items,
-
3:19
and we want to smartly cache the first item's details.
-
3:24
We actually want to do a second request to get the first item,
-
3:29
so if the user clicks on the first item, it instantly gets the details of that first item.
-
3:34
If we have to do this traditionally—is this visible?
-
3:41
I can zoom in, I think.
-
3:48
It doesn't work, but I have abstracted the Ajax call to get the Ajax function.
-
3:55
I get a list, and when it gets back
-
3:59
I have to call back, and we check the results there,
-
4:03
and I'm going to do this, and then I have a handle failure.
-
4:06
It's really just quite abstract.
-
4:10
So if we continue, we want to get the details as well.
-
4:15
We do the getAjax, and we get the list,
-
4:18
and we see if the list is there, and we do the second request,
-
4:21
and if the second request returned,
-
4:24
in the callback we will call the cache result,
-
4:29
so if the user clicks it it will be right there.
-
4:33
Yeah, we're in so-called callback hell now,
-
4:39
and this is just a simple scenario.
-
4:42
If we want to go deeper,
-
4:44
this gets worse and worse and worse.
-
4:47
If we want to solve this with promises,
-
4:49
we are going to do it like this.
-
4:53
We get the list, and then we call the getAjax call.
-
4:57
It now returns the promise, and we can call then,
-
5:01
and then takes 2 parameters.
-
5:03
The first is the success callback,
-
5:07
and the second one is the failure callback.
-
5:10
The cool thing is that I do not have to call them immediately.
-
5:15
I can say, "Okay, I'm going to fire off this Ajax call,
-
5:19
and then I'm going to do some other stuff," and finally, when I'm ready for it,
-
5:24
I call the then, and it will return immediately, of course, still asynchronously.
-
5:30
Or if it still has to wait for the request to finish, it will return later.
-
5:38
If we continue on our example, I get the list again.
-
5:43
Then if we have a success,
-
5:46
we are going to get the detail page,
-
5:48
and then we are going to chain them.
-
5:52
The second result is down here.
-
5:58
When the first is done, the second then will trigger,
-
6:02
and so we can actually cache the result.
-
6:04
This is a much more readable code.
-
6:08
This is another example that is really cool.
-
6:10
You can also do promise.all.
-
6:15
I have a little example here that it doesn't really do much,
-
6:20
because I have made a function that returns a promise right here,
-
6:24
and it finds out for X milliseconds,
-
6:30
and when it's done it calls the resolve function.
-
6:32
This is really basic, because I don't handle the reject case,
-
6:36
and so what I can do now is I can ask promise.all sleep 5 seconds
-
6:43
and another one for 2 seconds.
-
6:46
And if we're all done, this one gets called
-
6:50
with an array of return values of these.
-
6:54
And the failed ones we'll get back here.
-
6:58
If you want to do this with callbacks,
-
7:00
you'd have to write codes that in every callback it would check via a global variable
-
7:06
if the other callback is already done,
-
7:08
and if I'm the last, I will now execute this code.
-
7:12
This is really hard to do without promises.
-
7:18
I've been talking about promises, and they have been around quite some time,
-
7:22
so you have Q as an implementation.
-
7:26
RSVP is another one.
-
7:28
JQuery.deferred has been around quite long,
-
7:32
but it's not really adhering to the spec,
-
7:35
but it's a way to handle promises.
-
7:43
These are our native promises,
-
7:45
and I found this tweet, and the eventual part is the amazing thing here,
-
7:53
because if the browser will use promises,
-
7:57
you can ask for the screen with WebRTC, for instance.
-
8:03
You have to ask permission, and then you can fire that off
-
8:06
and wait for it to return.
-
8:11
We currently use promises in Firefox,
-
8:14
in Safari, and in Chrome 32 and up.
-
8:18
I think Chrome 32 is the current Canary,
-
8:21
and it's actually going to come to IE,
-
8:25
because IE has publicly decided they will want to support this.
-
8:31
Continuing on to another little API.
-
8:36
This one is actually an API.
-
8:38
It's called ambient light events,
-
8:41
and this is its definition.
-
8:44
When a device's light sensor detects a change in the light level,
-
8:48
it notifies the browser by firing the DeviceLightEvent.
-
8:51
Once the event is captured, the event object gives access to the light intensity expressed in lux.
-
8:57
Lux is a way to measure light.
-
9:03
I'm going to have to switch browsers now.
-
9:05
This does not work in Canary.
-
9:11
So what I'm going to do, I'm going to start the demo now.
-
9:16
I'm plotting out the values of the light sensor,
-
9:21
and the thing is, I don't have a flat light,
-
9:28
but I'm holding my phone on there, and once the sensor detects light that is lighter,
-
9:39
you saw it flashing white, so what you can do is change the coloring
-
9:45
of the contrast of your page by looking at how bright the user is,
-
9:55
how bright the location is where the user is.
-
9:59
Sorry.
-
10:04
But how would this look in code?
-
10:07
It's really simple, because we add an event to the window,
-
10:12
and we listen for the device light event.
-
10:15
And when the value changes, we can plot out the event of the value,
-
10:21
and the example you just saw of changing the background color is like this.
-
10:28
When the lux value goes below 50,
-
10:31
it will add a class darklight to the HTML element,
-
10:38
and if it gets above that, we will add brightlight and remove the darklight.
-
10:43
We can actually switch based on the light intensity.
-
10:50
This is currently working on multi Firefox,
-
10:54
and it doesn't currently work on Windows,
-
10:57
but I read they're working on that, but it works on Firefox OS and Firefox for Android.
-
11:03
And if you research it, there is a pretty cool movie on what other things you could do with it.
-
11:12
That was DeviceLight API.
-
11:14
Another small one is Vibration API.
-
11:17
This background image, I know you probably think about different images,
-
11:22
and I thought to keep it family friendly.
-
11:26
This is really simple.
-
11:28
I can't really demonstrate this because most laptops
-
11:33
don't have vibrating devices in them, but it's really easy.
-
11:37
You just call navigator.vibrate
-
11:39
and the number of milliseconds you want it to vibrate, and there you go.
-
11:43
You can also make patterns,
-
11:45
navigator.vibration, and you pass it an array,
-
11:48
and then every second element in the array is paused,
-
11:54
so in this example you would vibrate for 100 milliseconds
-
11:57
and then pause for 50 and continue for about 100.
-
12:02
There are, of course, some security measures built in,
-
12:09
like in the specification you cannot activate the vibration
-
12:14
when you're not the visible page.
-
12:16
Most of the browsers have implemented limits
-
12:20
on the time you can actually use, you can vibrate on end.
-
12:29
You can currently use this on Firefox and Android
-
12:31
and Chrome 32 on Android, and it's going to be in Chrome 32.
-
12:38
You cannot actually install this at the moment, I think,
-
12:41
from a run-of-the-mill marketplace, but it's going to be in there.
-
12:47
The big gap here is, of course, iOS and Safari.
-
12:51
It's a bit sad, but it's how it is.
-
12:57
Web speech API.
-
12:59
This is also pretty cool.
-
13:03
I'm going to have to switch browsers again
-
13:06
because this one actually only works in Safari.
-
13:09
Let's see if I can turn up the volume a bit.
-
13:13
[computer] Hello Sideview Attendees.
-
13:17
Great, this really makes me feel like in those '95 days
-
13:22
when you could make these—digital basic script these talking avatars.
-
13:30
But it's really cool that we have these.
-
13:36
It's also pretty simple.
-
13:38
You set up an utterance.
-
13:42
The class name is a bit long, but what can you do about that?
-
13:46
SpeechSynthesisUtterance, Hello SideView Attendees,
-
13:49
and then we set up how we want this to be set.
-
13:53
The volume is set to 1.
-
13:56
The rate of the speech, how fast it's going, and pitch is how high,
-
14:02
and the language you want to have it pronounce it.
-
14:07
And in the end, you just say window.speechSynthesis.speak,
-
14:11
the utterance we just created.
-
14:15
There in the specification you can also specify
-
14:20
what voice you want to use, if you had a voice URI,
-
14:25
but that does not seem to work anywhere at the moment.
-
14:30
This is just one part of the web speech API,
-
14:35
because this is output, or synthesis.
-
14:39
The second part is recognition
-
14:42
and this is also where you—like you have seen for TVs.
-
14:49
You can actually do this in the browser.
-
14:51
Currently I think it's only in Chrome.
-
14:53
This needs an Internet connection, so I cannot really demonstrate this right now,
-
14:59
but it's a bit more complicated.
-
15:04
We initialize a new webkitSpeechRecognition object.
-
15:09
You see its prefixed with webkit there.
-
15:12
We tell it we want to have continuous recognition,
-
15:15
so if we stop speaking it doesn't stop,
-
15:18
so we can keep on talking, and it will keep on recognizing what we are saying.
-
15:24
The language we're talking.
-
15:26
We want to have interim results.
-
15:28
This means that even if the result is not yet final
-
15:32
because the recognition process takes a while to get to a final result,
-
15:39
like you are saying a word, so it makes an assumption of what you're going to say,
-
15:46
and in the end, we'll get a final result for that word or sentence.
-
15:51
And then we start it, so we could start talking,
-
15:53
and we have there the end result event handler,
-
15:57
and in there we can do all kinds of things
-
16:00
from the input we get.
-
16:03
And when we are done recognizing, we just stop.
-
16:12
This currently works in Chrome 25 and up.
-
16:15
It's only the input part,
-
16:17
and you need an active Internet connection,
-
16:19
because the recognition is actually happening on the Google service.
-
16:25
The output part, as you just saw before,
-
16:29
works on Safari 6.1 and up on desktop and on iOS7,
-
16:36
and this API is coming to Firefox,
-
16:39
and the speech synthesis part is also in Chrome 33
-
16:44
that's going to be the next Canary.
-
16:46
I just saw a tweet last night that this will be in Chrome 33,
-
16:49
so it's pretty neat.
-
16:53
I'm going pretty fast.
-
17:00
I have 2 more left, but first of all, I lied.
-
17:03
I said I wouldn't be talking about WebRTC.
-
17:08
I just saw this demo a couple of weeks ago,
-
17:11
and it was like yeah, I wanted do this really a long time,
-
17:14
because it's so annoying that I have to use Skype to share my screen
-
17:18
with my remote co-worker, so there was this demo in Chrome
-
17:24
that you can share your screen.
-
17:26
There are some limitations, though.
-
17:28
You can only use it on an HTTPS server.
-
17:32
This is probably a good thing, because you wouldn't want your screen to be shared
-
17:36
on a regular HTTP connection where everyone may be listening in.
-
17:45
It pops up this, "Do you want to share your screen?"
-
17:47
Yes, I want to.
-
17:49
I'm displaying here—I can go like this.
-
17:58
It's pretty neat.
-
18:01
I'm going to stop sharing now.
-
18:03
And it also works in the basic navigator.getUserMedia.
-
18:10
But apart from that, we are not asking for a video.
-
18:14
We're actually telling the browser what video source we want to use,
-
18:19
and this is the chromeMediaSource stream,
-
18:21
and then we got the stream here,
-
18:25
and we output it to a video element,
-
18:27
and we append that to the body.
-
18:30
This just works in Chrome 26 and up.
-
18:37
But it's really cool, and I hope other browsers will implement this.
-
18:45
This is the last thing I'm going to talk about today, the ServiceWorker, and I'm really excited about it.
-
18:51
By the way, this is not a slide I created.
-
18:53
This is a slide Bruce Lawson from Opera uses,
-
18:57
and he showed this at the Fronteers Conference in the Netherlands,
-
19:00
but when I was looking at this slide I was like, "Whoa,
-
19:05
if I ever talk about ServiceWorkers, I want this slide,"
-
19:09
so I asked him if I could use it, and he said yeah.
-
19:12
So what are ServiceWorkers?
-
19:15
I'm really excited about those.
-
19:17
ServiceWorkers allow us to persistently cache
-
19:20
resources and handle requests to these resources
-
19:23
even when the network isn't available.
-
19:27
This means we can make offline apps.
-
19:30
You'd say, "Yeah, okay, but we've got appcache
-
19:33
or other caching mechanisms for the app."
-
19:36
But the thing is, with appcache it's decorative.
-
19:39
There are a lot of drawbacks.
-
19:42
We have to think up front what we want to cache,
-
19:47
and then once it's cached,
-
19:49
we are having a lot of trouble getting it out of the cache.
-
19:53
And ServiceWorkers give us a way to—if we fire code, to control this mechanism.
-
20:02
They consist of 2 parts,
-
20:04
a shared worker/controller that lives across page loads
-
20:09
and a programmable HTTP cache.
-
20:17
A little example of how this would work.
-
20:20
On the first page load you're going to register the ServiceWorker.
-
20:25
We're saying we want to handle everything on /*
-
20:32
with this controller.
-
20:36
And as you see here, they are using promises.
-
20:39
Once it has been registered and initialized,
-
20:43
it will handle all subsequent requests on this domain.
-
20:50
That's why it says here if you want to use ServiceWorker immediately,
-
20:54
you might call window.location.reload
-
20:56
because that would mean that the current HTML page
-
20:59
also would be handled by this ServiceWorker.
-
21:05
This is what the worker looks like.
-
21:08
It's pretty much like a ServiceWorker.
-
21:10
I'm going to run through this code really quick.
-
21:16
We have here base URL and inventory URL.
-
21:20
We have the install event listener,
-
21:24
so on the previous slide we called the register function,
-
21:31
and everything worked well.
-
21:33
In the worker the install event gets called,
-
21:36
and in the install event we are telling the whole mechanism
-
21:42
yeah, we are handling fetch here.
-
21:45
This is something—actually, I talked to Alex Russell last night from Google.
-
21:51
He is working on this, on the spec,
-
21:53
and this is something that may look a bit weird right now,
-
21:59
but there will be more events for streams,
-
22:03
for instance, in the future.
-
22:07
And then we listen to this fetch event and see what comes in.
-
22:11
This is really just a basic example
-
22:14
to see when we have a request for services inventory data JSON.
-
22:23
We are going to respond with an empty JSON object right here,
-
22:29
so this is pretty useless, but you can imagine what you could do with it,
-
22:34
like stuff like it's really hard to do right now when you have also a news app,
-
22:40
and if you open the app, you want to have an immediate result on there,
-
22:48
so you show them the cached result you already have,
-
22:53
and in the meantime, in the worker you're going to fire off a request
-
22:58
to get more data or newer data.
-
23:00
And if this does not work—
-
23:03
and if it comes in, you can update it.
-
23:05
And if it doesn't work, you maybe get a generic error,
-
23:08
and you say at the bottom of the page that's why we cannot load any new data
-
23:11
because you may or may not be online, or there may be something wrong with your connection.
-
23:19
The thing is, this is just the specification right now,
-
23:26
and it's in flux, but I'm really excited about this one.
-
23:30
This is going to happen. It's really cool.
-
23:33
When I started researching this for this presentation,
-
23:36
I was looking into if it worked in Chrome, and there is some basic scaffolding code in there,
-
23:45
because the primitives are there,
-
23:48
but it doesn't really do anything.
-
23:53
But there is a lot of stuff going on around these ServiceWorkers.
-
24:01
Previously they were called navigation controllers,
-
24:04
and what you see here is a Google+ post by Paul Irish,
-
24:09
and he links to the intent to implement for Mozilla.
-
24:15
They're also into this, and Chrome is obviously working on it,
-
24:19
so this is going to happen I hope next year.
-
24:25
These were my 6 little things.
-
24:27
There is much more I could not cover in this talk.
-
24:31
The Midi API.
-
24:33
It basically means if you're into music
-
24:37
you could dig garage bands.
-
24:39
You could do all this in your browser,
-
24:41
have your keyboard input directly to your—
-
24:47
battery Status API, it's been around quite a while.
-
24:49
It's also pretty simple,
-
24:51
a little API, but you can do fun stuff with it
-
24:55
like when your battery is dying
-
24:59
you can quickly save some stuff.
-
25:01
The Web Crypto API and the URL object.
-
25:05
This has been standardized pretty recently.
-
25:10
These were some of the things,
-
25:14
and I think we as web developers should look into this.
-
25:17
Most of the time we're busy making money
-
25:23
or making money for our clients, and we have to stick to stuff that works,
-
25:30
but I think we need to do this.
-
25:33
We need to research this. We need to do experiments with these APIs.
-
25:37
Not only to get them improved,
-
25:40
because just last night I was talking about the ServiceWorker with Alex Russell,
-
25:45
and he was asking me what I thought about it,
-
25:49
because they want to have the input to improve this
-
25:52
and make it actually usable, and if we use and experiment with this,
-
25:58
browser vendors have more incentive to implement them
-
26:01
so we will never get into an IE6 situation anymore.
-
26:06
This was my talk.
-
26:10
I'm doing pretty well on schedule, I think.
-
26:13
Thank you very much.
You need to sign up for Treehouse in order to download course files.
Sign up