W3C home > Mailing lists > Public > public-digipub-ig@w3.org > May 2015

Re: Notes on Web and Service Workers

From: Ivan Herman <ivan@w3.org>
Date: Wed, 13 May 2015 11:46:30 +0200
Cc: Tzviya Siegman <tsiegman@wiley.com>, Markus Gylling <markus.gylling@gmail.com>, W3C Digital Publishing IG <public-digipub-ig@w3.org>
Message-Id: <496B7E05-D1EF-41A5-AB5D-716A683435EF@w3.org>
To: Nick Ruffilo <nickruffilo@gmail.com>

> On 12 May 2015, at 16:15 , Nick Ruffilo <nickruffilo@gmail.com> wrote:
> 
> Ivan,
> 
> Web/Service workers can be some seriously complex topics, especially if you don't come from a computer science/linux background, but I'll try to explain them in completely "human" terms.
> 
> Imagine your web page - instead of being a bunch of HTML/CSS/Javascript, being a person - lets say ME.  (obviously this is a bit of a simplification, but you'll get the point) When you first access that website, I create outlines for the objects based on the HTML code.  Then, I paint and manipulate how those objects based on the way they look (that's the CSS).  I'm one person, so I can only do one thing at a time.
> 
> Next, once everything is laid down, I get to "work" (javascript).  As your mouse moves I check my list of instructions to see if I should be triggering an interaction, etc.  But I'm only 1 person.  Technically you can have me complete multiple tasks (have a clock that displays the time, play an animation, etc) but, for the most part, I have to figure out how to manage all of that with my arms and legs.
> 
> In comes "Web/Service workers."  Lets say I'm getting really tired, I can call a "Web Worker" (temporary labor) to come handle some tasks for me.  Since this is a new person, they can handle the tasks independent of what I am doing.  Since a web-worker is temporary labor, they will go away as soon as you close that page.
> 
> Then we get into Service Workers.  Service workers are like butlers - they stick around even if you leave the page.  So, if you ask them to make you a sandwich (because you're so hungry from running so much javascript) the user can close the page, then come back later, and the butler is ready with the sandwich.

Actually, it is a bit even more than that. If you ask for a web page, that usually means that you ask a courier to go out and get that page for you from your neighbour (for example). Depending on how you set up yourself, you may have to wait, twiddling your thumbs, until the courier comes back, or you can try to make something useful until that happens. However, the courier is just a simple job: get the address, go to the neighbour, ask for the content, return.

A service worker may also act as an smart courier that you can instruct to do something more complex. So when you ask for a page, the smart courier may decide to go out and fetch the content for you but, once the content has been delivered, it stores it in your home. Next time he is asked to deliver the same content, he will simply pick up the content in your home instead of visiting your neighbour. Ie, if the doors of your mansion are closed (a.k.a. you are offline) the content will still be delivered, and you do not even realize that your cut from the outside world…

Ivan

> 
> Ultimately it comes down to THREADs.  A thread is a "line" of functions.  Most of programming is linear: Execute this code, then move on to the next.  Repeat.  The issue is that if one task takes a long time, everything AFTER that gets delayed.  Creating a 2nd thread means work can still get done.  Today's chips can easily handle multi-threaded operations and excel at it.  Web workers are a way to easily define threads, whereas in the past you had to do it in a very "hacky" way using timers (in javascript).
> 
> Hopefully this clears things up.  If anyone spots a flub by my explanation, please let me know!
> 
> On Tue, May 12, 2015 at 8:24 AM, Ivan Herman <ivan@w3.org> wrote:
> Tzviya, Markus,
> 
> I have spent some time trying to get *some* idea on what Web Workers and Service Workers are. They are spinning my head and I am sure there are many details that I simply did not understand. Nevertheless, I thought it is worthwhile jotting them down separately, because they might affect the whole EPUB-WEB discussion:
> 
> https://github.com/w3c/epubweb/wiki/Notes-on-Web-and-Service-Workers
> 
> I would be pleased if somebody on the group, who has a better understanding of these, could comment/update the file!
> 
> Ivan
> 
> ----
> Ivan Herman, W3C
> Digital Publishing Activity Lead
> Home: http://www.w3.org/People/Ivan/
> mobile: +31-641044153
> ORCID ID: http://orcid.org/0000-0003-0782-2704
> 
> 
> 
> 
> 
> 
> 
> --
> - Nick Ruffilo
> @NickRuffilo
> http://Aerbook.com
> http://ZenOfTechnology.com
> 


----
Ivan Herman, W3C
Digital Publishing Activity Lead
Home: http://www.w3.org/People/Ivan/
mobile: +31-641044153
ORCID ID: http://orcid.org/0000-0003-0782-2704





Received on Wednesday, 13 May 2015 09:46:44 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 25 April 2017 10:44:25 UTC