I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...
That tech is known as "comet", but also as "server push", "reverse ajax", etc.
ReplyDeleteIt's about pushing data from the server to the browser, keeping an http connection alive. Find more info on it on the wikipedia article (English version).
Also here's a pretty good presentation with Joe Walker from DWR, where he talks about comet.
As you rightfully pointed out, HTTP requires data to be 'pulled' by the client. Gmail can still 'pull' data from the server by using a timer to trigger the HTTP operation instead of requiring the user to click something. So, it may seem to be auto, but it is still client initiated.
ReplyDeleteYep Comets is correct. Google Web Toolkit Applications by Ryan Dewsbury explains how to create a Comets based Instant Messenger application in chapter 9.
ReplyDelete