Psyche
Psyche

Reputation: 8773

Unresponsive script - is it possible to avoid it?

I have a listing with 150 rows and for each row there are three skinned select items.

Because there's heavy processing to be done before displaying each result I get an error saying "A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete." and it refers to jquery.js file.

Is it possible to avoid this error by doing some jQuery work?

Thank you.

Upvotes: 6

Views: 2720

Answers (4)

Vishal
Vishal

Reputation: 2181

Download JavaScript as and when required, instead of downloading it all on page load.

On Demand JavaScript

Upvotes: 0

Koen Peters
Koen Peters

Reputation: 12916

Website performance guru Steve Souders wrote about this problem and how to solve it in his book "Even faster web sites". He describes a solution where you use timeouts to let other processes get some time as well.

Here's the part of the book that deals with this problems.

Upvotes: 0

ThiefMaster
ThiefMaster

Reputation: 318518

You need to split your processing into multiple parts and give the browser some time to do stuff besides them by using a 0 or 1 msec setTimeout.

A very easy method would be using the forEachSeries method of the async library:

async.forEachSeries(yourData, function(item, cb) {
    // process item
    async.nextTick(cb);
});

yourData could be the jQuery object containing your rows, then item will be the DOM element of one row.

Upvotes: 6

Sirko
Sirko

Reputation: 74056

I don't know about jQuery (if there is some wrapper available in jQuery), but in vanilla JS there is the concept of WebWorkers (support is rather good except for IE - see here).

Here you start an extra thread to to you computations, that does not block your UI thread. When the computations are done and just the result display is left over, you send the data from the worker to the UI thread and just display the results.

For details, have a look at the MDN tutorial.

Upvotes: 0

Related Questions