Array

Web Workers

Must Read

GRAD PLUS and Private Student Loans FAQ

1. Comparison of Grad PLUS or graduate student loans with Private LoansInterest Rates - While GradPLUS or graduate student...

How a Home Equity Loan Refinance Can Save You Money – Should You Refinance Your Texas Home Loan?

In Texas you can refinance your home as well as your investment property. And with today's low mortgage rates,...

Getting Out Of Debt – Best Debt Consolidation Loans

If you find yourself struggling to stay afloat in a world of debt, you have probably considered loan consolidation....

Student Loan Consolidation Comparison – 3 Tips

Almost every student who graduates from college is burdened with the debt of student loans - often for years...

Home Equity Line of Credit – Get Cash From Your Home

Have you been spending a fortune improving your home? Then it is about time to count your money in...

Advantages Of Business Marketing On Facebook

The advantages Facebook offers are too much to be listed out and it makes people understand why it is...
Admin
test

Web Workers6 are not part of the HTML5 specification, but you may find them useful if you need to do some background processing on the client side, so they’re worth mentioning.

We use JavaScript for all of our client-side coding, but JavaScript is a single-threaded language—only one thing can happen at a time. If a task takes a long time, we force the user to wait until the task has finished. Web Workers solve this problem by creating a simple way to write concurrent programs.

If we have a script called worker.js that does some image processing, we can invoke it like this:

var worker = new WorkerC”wor/cer. j s ” ) ;

Any JavaScript file can be launched as a worker, but in order for the worker to be independent, your worker script can’t access the DOM. That means you can’t manipulate elements directly.

Our main script can send messages to the worker script using postMessage() like this:

$(“#button”).cli ckCfunction( e v e n t ){
$ C ” # o u t p u t ” ) . h t m l ( “starting…”);
w o r k e r . p o s t M e s s a g e ( ” s t a r t ” ) ;
} ) ;

Our worker script can then send messages back to the main page, also using the postmessage() method.

onmessage = function(event) {
i f C e v e n t . d a t a === ” s t a r t ” ) {
/ / t h i s loop counts. Do something awesome i n s t e a d ,
for (var x = 1; x <= 100000; x++){
postMessage(x);
}

We respond to those events by listening to the onmessage event in our main script. Every time the worker posts back, this code will fire:

worker.onmessage = function( e v e n t ) {
$(“#output”).html(event.data);
}

This API works just like the API for cross-domain messaging, which we talked about in Talking Across Domains, on page 200. There’s no support for Web Workers in Internet  Explorer, so you’d need to rely on Google Chrome Frame, but if you’re looking to do some heavier nonblocking client-side work, you’ll want to look into this further.

 

 

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place at the...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when was the...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial as well...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though he had...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost everyone needs...

More Articles Like This