Thursday, 19 September 2013

How to run javascript function in "background" / without freezing UI

How to run javascript function in "background" / without freezing UI

I've done an html form which has alot of questions (coming from a
database) in many different tabs. User then gives answers in those
questions. Each time a user changes a tab my javascript creates a save.
The problem is that I have to loop through all questions each time the tab
is changed and it freezes the form for about 5 seconds every time.
I've been searching for an answer how I can run my save function in
background. Apparently there is no real way to run something on background
and many recommend using setTimeout(); For example this one How to get a
group of js function running in background
But none of these examples doesn't explain or take into consideration that
even if I use something like setTimeout(saveFunction, 2000); it doesn't
solve my problem. It only postpones it by 2 seconds in this case.
Is there a way to solve this problem? Thank you in advance.

No comments:

Post a Comment