Stas Bichenko
Stas Bichenko

Reputation: 13263

Javascript code freezes page for a while -- how do I prevent this?

I have a fairly CPU-intensive script which, when run, freezes the whole page for a while, so that it can't be scrolled or clicked, etc. I would gladly sacrifice performance for a more smooth experience.

Also, in my case, this script is a part of Google Chrome extension.

Is it possible to make a script that freezes the page run in background, without interrupting user interaction with the page?

Upvotes: 0

Views: 190

Answers (1)

Thomas Junk
Thomas Junk

Reputation: 5676

Maybe web workers are of interest.

It would be best to put CPU-intensive task into a worker, which does its job in the background. Another solution is to cut your code into pieces, load them asynchronously and execute them one after another.

http://blog.typekit.com/2011/05/25/loading-typekit-fonts-asynchronously/

Upvotes: 2

Related Questions