Throttling server-side call based on keyup


I have a Method call (server-side) that queries an external API on keyup, not the best in terms of performance and I’m hitting the API pretty hard. Is there some way to throttle the method call? Essentially waiting with the request until a certain delay has passed after the last keystroke.


I’d probably do it something like this:

Template.something.onCreated(function() {
  this.debounce = null;
  'keyup input#some-id': function() {
    var instance = Template.instance();
    if (instance.debounce) {
    instance.debounce = Meteor.setTimeout(function() {;
    }, 200);


Great, thanks! :smile:


@robfallows is right, you’ll want to debounce your function… Since underscore is part of core though you might as well use underscores debounce function{
  'keyup input#some-id': _.debounce(function() {
     //code here
  }, 200);

edit: fix typo => _debounce


That is much more compact :smile:.

However, you should add the underscore package to your app if you use this (even though it’s currently in the core).


I have debounce as package too and using it this way, which way is the best from compatibility point of view?{
     "keyup #searchStreamer": _.debounce(function (event, template) {
    	RunSearch({searchStreamer:, searchSkip: 0});

use _debounce, or _.debounce or how? :smiley:


Well spotted: _.debounce() is correct:



that’s great. thank you