This is very cool - good find!
It looks like this is mostly but not entirely supported. See here:
Specifically it looks like Firefox, Internet Explorer, and Safari do not implement this attribute, so I’d suggest a try-except just in case. I usually use window.innerWidth <= 640
as a check.