var profilesToLoadAtATime = 18;
var numberLoaded = 0;
var loadingMore = false;
var startTime = Math.floor(Date.now() / 1000);
// lazy load teachers by last name
var scrollRef = new Firebase.util.Scroll(ref, 'lastName');
scrollRef.on('child_added', function(snap) {
appendTeacher(snap);
numberLoaded += 1;
if(numberLoaded % profilesToLoadAtATime === 0) {
$('.search-info').hide();
loadingMore = false;
console.log('Time taken = ' + (Math.floor(Date.now() / 1000) - startTime));
}
});
scrollRef.scroll.next(profilesToLoadAtATime);
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 800) {
if(!loadingMore) {
console.log('loading more profiles...');
startTime = Math.floor(Date.now() / 1000);
loadingMore = true;
scrollRef.scroll.next(profilesToLoadAtATime);
$('.search-info').show();
}
}
});
Basically the first load is quick.. 2 seconds. Then calling scroll.next() again.. quick 3 seconds.. then the load times start to jump right up.
Sample output...
loading more profiles...
Time taken = 2
loading more profiles...
Time taken = 3
loading more profiles...
Time taken = 6
loading more profiles...
Time taken = 23
loading more profiles...
Time taken = 13
loading more profiles...
Time taken = 17
loading more profiles...
Time taken = 17
loading more profiles...
Time taken = 15
loading more profiles...
Time taken = 17
loading more profiles...
Time taken = 22
loading more profiles...
Time taken = 24
loading more profiles...
Time taken = 36
loading more profiles...
Time taken = 21
Here is an example how I am using this library
Basically the first load is quick.. 2 seconds. Then calling scroll.next() again.. quick 3 seconds.. then the load times start to jump right up.
Sample output...
loading more profiles... Time taken = 2 loading more profiles... Time taken = 3 loading more profiles... Time taken = 6 loading more profiles... Time taken = 23 loading more profiles... Time taken = 13 loading more profiles... Time taken = 17 loading more profiles... Time taken = 17 loading more profiles... Time taken = 15 loading more profiles... Time taken = 17 loading more profiles... Time taken = 22 loading more profiles... Time taken = 24 loading more profiles... Time taken = 36 loading more profiles... Time taken = 21
Any idea why? Am I missing something? Thanks.