Re: Notes on Web and Service Workers

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.

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 <http://zenoftechnology.com/>

Received on Tuesday, 12 May 2015 14:16:16 UTC