title: How to performance tune AJAX heavy application
body: <p>I'm developing kind of image/profile search application, that is based almost exclusively on AJAX. Main page basically displays profile images and allows user to filter/search and paginate through them.</p>
  
  <p>Pagination works when user scrolls, so the <strong>interface has to be very very fast</strong>. There will be only 6 (maybe 9, but definitely not more) images displayed on the main page, so users will scroll a lot. I'm currently using very simple JS cache to store results of all the requests in case user decides to go back ... in that case, I simply pull everything out of the cache instead of querying the server.</p>
  
  <h1>Client cache</h1>
  
  <p>One option that I thought of is to pre-load say 10 pages in front and store them in the cache.</p>
  
  <p>But <strong>my biggest issue is filtering/searching</strong>, since that completely changes the type of query that goes to the server. My filters aren't very complex, only around 6-7 string/number/enum attributes.</p>
  
  <p>Now if I wanted to do all the filtering in the cache, I would have to duplicate all the search logic and fetch all the data from the server (not just the data I'm displaying), so I could filter the results on client side.</p>
  
  <p>Here raises a question, should I make the cache somehow persistent? Store it into a cookie maybe?</p>
  
  <h1>Server cache?</h1>
  
  <p>One suggestion might be to <strong>use memcached on the server and just store everything there.</strong> I'm definiely going to cache away all the results I can, but that doesn't save the server from handling loads and loads of AJAX requests.</p>
  
  <p>I'm developing this application on Rails 3, and even though I love it, I wouldn't say it's the fastest thing in the world. <strong>Another option that this gives me is to create separate Rack/Sinatra application to handle only the AJAX requests.</strong> By this I mean requests from the main query, not all AJAX.</p>
  
  <h1>S3 for images?</h1>
  
  <p>Big part of this application are images, even though they're mostly small thumbnails (unless user wants to display it bigger).</p>
  
  <p>At the moment, I don't have problems with bandwidth. My VPS host provides me with 200GB, which should be more than enough (I hope). The problem is loading speed. Would it help if I uploaded all the images to S3 and load them from there, or is this worth doing only for larger files? I'm going to load <strong>a lot of 100x150px images</strong>, which are generally under 50kB.</p>