Real Questions:
1. Why do we need such timeouts in Javascript?
2. Is there any standard and elegant workaround for such timeouts?
3. What causes these inconsistencies because of timeout not put? Is that the order of the js files being downloaded or anything else?
Background:
If you need the background is like the following
We have a grid solution in place for the HTML tables.
This HTML table can be resized, some columns can be made hidden, columns can be dragged and dropped to change their ordering.
This all is implemented using javascript. Also AJAX request is fired on unload of the page so that whatever changes the user has made can
be stored in session. If user visits the same page again, then these settings from the session can be "reapplied" and user does not have to do it again in the same session.
This reapplication is done like the following - we paint all the HTML table and then on top of that we apply users settings from session, like hide this column and make another wider etc.
This is all working fine.
Now we wanted to introduce "default settings" for particular pages.
Like less needed columns can be default hidden and columns like description can be default wider and so on.
What we did was to read the default settings from a properties file and add them in the session when user first vists the page.
So that our "reapplying" logic will pick the settings [we save them in a hidden variable on the page] and next working will be as it is in the above case.
But the settings are not getting applied for no apparent reason.
We do not get a JS error or anything.
The wierd this is that if we add one alert somewhere, the issue disappears and the default settings are applied properly.
If we remove the alert, it does not work.
We figured this is a delay issue and added some delay using javascripts setTimeout method. It works fine when delay is applied.
But it is taking delay in seconds when onsite environment is accessed. Locally it runs with delay of about 1 ms.
Value your each suggestion. Thanks in advance!
Regards,