开发者

BIG Resource eater

This script is eating up a lot of resource on my members computers. I have other interval scripts that don't eat up any resource. I've tried extending the time but that slows down the refresh. Any suggestions?

<script type="text/javascript">
$('document').ready(function(){
  updatestatus();
  scrollalert();
});
function updatestatus(){
  //Show number of loaded items
  var totalItems=$('#scontent p').length;
  $('#stat开发者_开发百科us').text('Done');
}
function scrollalert(){
  var scrolltop=$('#scrollbox').attr('scrollTop');
  var scrollheight=$('#scrollbox').attr('scrollHeight');
  var windowheight=$('#scrollbox').attr('clientHeight');
  var scrolloffset=10;
  if(scrolltop>=(scrollheight-(windowheight+scrolloffset)))
  {
    //fetch new items
    $('#status').text('Loading more members...');
    $.get('allonline.php', '', function(newitems){
      $('#scontent').load('allonline.php');
      updatestatus(); 
    });
  }
  setTimeout('scrollalert();', 60000); 
}
</script>


Without seeing what's being brought back from 'allonline.php', I'm just guessing. But the one area that stands out is the fact that you have a $.get() function that requests 'allonline.php' and in it's callback you load() 'allonline.php' again. Seems like you're requesting the same chunk of data twice, but only using it once.

Can you replace

$.get('allonline.php', '', function(newitems){
    $('#scontent').load('allonline.php');
    updatestatus(); 
});

...with:

$('#scontent').load('allonline.php', function() { updatestatus(); });

You're not using newitems in your $.get() callback, so I think this should work.

Other things to check:

  1. size of response from allonline.php -- if it's large, and you're requesting it twice, it could take a browser some time to re-render the DOM;
  2. browser your clients are using...IE7 is SLOW, IE6 is SLOOOOWWWWWER;
  3. class of machine clients are using

Again, without knowing what's being returned, I'm speculating. But the double request to allonline.php seems to be a culprit.

I hope this helps. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜