I would maybe throttle this a bit so it only calls the function after a certain timeout period. 

Here's an example on bedrock: https://github.com/mozilla/bedrock/blob/master/media/js/mozorg/home-b.js#L17