title: Debounce search only if search term changes
body: <p>I'm working on a live ajax search field. So we have:</p>
  
  <pre><code>&lt;input type="search" id="search"&gt;
  </code></pre>
  
  <p>And I want to trigger the search once the user has stopped typing for 500ms. </p>
  
  <p>I got it working like this:</p>
  
  <pre><code>function throttle(f, delay){
      var timer = null;
      return function(){
          var context = this, args = arguments;
          clearTimeout(timer);
          timer = window.setTimeout(function(){
              f.apply(context, args);
          },
          delay || 500);
      };
  }
  
  $('#search').keyup(throttle(function(){
      // do ajax
  }));
  </code></pre>
  
  <p><strong>The problem is:</strong> if user holds <em>shift</em> key and releases it, the search will trigger regardless. So no new keys are added and the same search term was submitted. </p>
  
  <p>How can I make it so that it triggers only if a new character has been added/removed? </p>