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:
- 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;
- browser your clients are using...IE7 is SLOW, IE6 is SLOOOOWWWWWER;
- 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!
精彩评论