For the longest time, I used
Can I Use says support is in all modern browsers, except IE9 and below, which you should have already stopped supporting.
This chunk of code below, tests for
matchMedia support, and adds listeners for changes. In this case, is listens for when the width of the window.
Below, is the functions called when the match changes. It’s fairly self explanatory I hope?
I believe the queries it can listen for are the same as CSS media queries, so there’s plenty of uses here. But, I would use Modernizr to test for features and environments, but
matchMedia for dimensions like I have above.