aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes setInterval Overhead Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "setInterval Overhead" Watch "setInterval Overhead" New topic
Author

setInterval Overhead

Nilabhra Banerjee
Ranch Hand

Joined: Mar 17, 2004
Posts: 34
Hi everybody,

I have written a script in the body which will write a cookie with very short expiry at certain interval. I have used setInterval to achieve this. Now, I would like to know

a) whether it carries any significant overhead in terms of memory and processing time.


<script language="JavaScript">
writeCookie();
timerId = setInterval("writeCookie()", 3000);
</script>

b) I am creating the cookie with expiry as current-time + 4 second. I am recreating the cookie with script, as you can see, every 3 seconds.
My page takes 2 seconds to load (lots of data). If I decrease the expiry to 2 seconds and interval to 1 seconds, will the next interval sequence fire before the page loads?


Thanks and regards
Nilabhra Banerjee
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Can I ask you what is the purpose of doing this? Sounds like you are recreating a basic session cookie which expires when the browser closes.

Eric
[ July 11, 2006: Message edited by: Eric Pascarello ]
Nilabhra Banerjee
Ranch Hand

Joined: Mar 17, 2004
Posts: 34
Yes, you are right. And I could have also wrote it down in onload or onunload of the body. But there are restrictions on doing it.

Scenario is like this, my welccome page needs to identify whether any page from the application is open or not. if open, that already open page needs to be popped up and focused. To identify this I need a session cookie, but unfortunately a session cookie for a browser window is not available another browser window. So I have to save it.

Neil
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
How are you opening up another window that is not reading the session cookie? I am assuming a pop up window....

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: setInterval Overhead