4

Currently I use this...

setInterval(function() {
    $.ajax({
        url: 'data.php',
        success: function(data) { document.title = data;},
        dataType: 'text'
    });
}, 15000);

But it seems to slow down the server due to the amount of queries to the server.

Is there another way of displaying the amount of unread messages in the title bar, without the overload?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Andy
  • 153
  • 8
  • One way is to run the script when focus is returned to the window. Of course, this would not make the new number of messages show in the tab/page title if they never visit the tab. – Mattis Sep 17 '11 at 17:50
  • Maybe a combination with a longer interval in your code there. Like 10 minutes or something ;) – Mattis Sep 17 '11 at 17:56
  • No matter what you do on the client, you're going to have to run the code that determines whether there are unread messages or not. Focus on improving *that* code. – evan Sep 17 '11 at 18:23

2 Answers2

1

These solutions come to my mind:

  1. Using Server-Sent Events (Which of course, reduces scalability due to open network connections)
  2. Using Page Visibility
  3. Comet programming
  4. Explicitly offering this feature on user's demand (so that many users won't even request for it)
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • Page visibility will be very useful to me for something else, so thanks for posting that. Although, I don't think it will be useful for what I posted above, as if the user isn't on the tab, the unread messages will not update in the title. – Andy Sep 17 '11 at 17:58
  • The page visibility actually was perfect. Exactly what I needed. Thanks – Andy Sep 20 '11 at 18:43
0

ideal for Comet (long polling)! Add a Nodejs in the backend.

Arjun
  • 1
  • 1