HTML and CSS Reference
In-Depth Information
type as well as the standard events. You can
look at the type-specific example in ch05/ microdata-api-3a.html.
Lag-free interfaces with web workers
All JavaScript in a browser has traditionally been run in a single exe-
cution context (a thread in operating system terms). That changed with
the release of IE8 , which separated the execution of interface code and
web-page code, and then the launch of Google Chrome, which was
built from the ground up to be multithreaded. Other browsers have
since followed suit. This made browsers quicker, more responsive, and
more resilient to bad or malicious code, but all the JavaScript in a sin-
gle page still used the one thread assigned to it. There was no way for a
web author to take advantage of multiple threads to offload expensive
processing to another thread while still responding to user input, as
they could in a desktop application. For this purpose, web workers
were created.
Single-threaded and multithreaded
Single-threaded means the web browser does only one thing at a time. After it
starts executing a single JavaScript function, it carries on until that function is
finished. While it's executing the function, the browser can't do anything else:
respond to clicks, animate GIFs, scroll the page, and so on. This isn't unusual; if
you have an old computer with only a single processor with one core, it can only
do one thing at a time too. One of the primary jobs of an operating system is to
switch between applications so quickly that the computer appears to be doing
more than one thing at a time.
Normally, each JavaScript function also executes so quickly that you don't no-
tice; but some heavy processing, a simple coding mistake, or even a malicious
script could bring the browser to a halt.
If the browser is multithreaded , it can take advantage of the operating system's
abilities to switch between tasks. If one thread starts eating up resources, the
browser can recognize this on another thread and take corrective action. The ad-
vent of multicore processors, which can do more than one thing at a time, also
opens up an opportunity to increase the performance of the entire browser by
splitting execution across multiple cores.
Search WWH ::

Custom Search