469,276 Members | 1,765 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,276 developers. It's quick & easy.

setInterval / setTimeout freezing browser?

57
Hi,
Has anyone seen this before? I have a "Now Playing" section for a radio station that displays what song is currently on the air. The on-air computer uploads an xml file with the song title, artist and album name. Then I use a javascript function that loads/displays the xml file and I've been using setInterval or setTimeout to have it update itself.

Here's the xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <audio>
  3. <title>Song Title</title>
  4. <artist>Artist</artist>
  5. <album_title>Album Title</album_title>
  6. </audio>
  7.  
Here's the javascript:
Expand|Select|Wrap|Line Numbers
  1. function nowPlaying() {
  2. xmlDoc = loadXMLDoc("xml/playlist.xml");
  3. title = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
  4. artist = xmlDoc.getElementsByTagName("artist")[0].childNodes[0].nodeValue;
  5. album_title = xmlDoc.getElementsByTagName("album_title")[0].childNodes[0].nodeValue;
  6. document.getElementById("nowPlayingText").innerHTML = title + " by " + artist + "<br />From " + album_title;
  7. setTimeout("nowPlaying()",5000);
  8. }
  9.  
The problem is that the page will "freeze" for a few seconds...I can't click on anything, can't scroll the page...nothing, and then it goes back to normal. Is this glitch just the browser freezing while it loads the xml file? I've noticed it in FF, IE, Safari, Chrome and Opera and whether I'm using either setInterval or setTimeout. Is there maybe a way for the javascript to wait and load the xml file only after it changes?

Thanks in advance!
Jun 1 '10 #1
1 4063
Dormilich
8,651 Expert Mod 8TB
Is there maybe a way for the javascript to wait and load the xml file only after it changes?
due to the stateless nature of HTML, a website doesn’t know, when a server file changes.

however, you can do an AJAX HEAD request (similar to GET) and read the "Last-Modified" header. if that value changed, you have a new file.
Jun 1 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Robert Mark Bram | last post: by
5 posts views Thread by Richard A. DeVenezia | last post: by
1 post views Thread by John | last post: by
2 posts views Thread by S.Hoitinga | last post: by
18 posts views Thread by Frances Del Rio | last post: by
1 post views Thread by James Black | last post: by
4 posts views Thread by E | last post: by
15 posts views Thread by nikki_herring | last post: by
2 posts views Thread by shawnwperkins | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.