weblinc/media-match

matchMedia

lkrids opened this issue · 8 comments

Why did you use Media.match instead of overriding matchMedia?

window.matchMedia = window.matchMedia || (function( doc, undefined ) { ... }

Wouldn't that provide a shorter path to the native matchMedia?

Good question @lkrids. I certainly could have but Media has a few things native doesn't, such as parseMatch, getAbsValue, and features. I was thinking that these "extras" could be used in other plugins or testing. I do provide window.matchMedia || (window.matchMedia = Media.match); on line 257 so users could still use features of Media and have a polyfill.

I've recently been thinking about a rewrite to make it just a matchMedia polyfill, rather than a polyfill plus these other features.

Have you experimented with Media yet?

I've already rewritten part of Media to speed up the initial parsing of the media query and each subsequent check that occurs on resize/orientation change. The initial parse is a tiny bit faster than what's on master now but a subsequent check is roughly 110 times faster. In OSX Chrome 23 that's around 33,000,000 operations per second. So now that the performance is there, I'm trying to make the rest of the code smaller. Even though matchMedia.js can't support IE < 9 and at last check it doesn't quite match spec, it is smaller. It's 1kb vs 3kb minified. I'd like to get into the low 2kb area.

I haven't experimented with Media yet in part because I just found this. I really like the idea of making this just a matchMedia polyfill with other stuff as optional extensions (maybe through a grunt build).

Yeah, I'll think about how and what should be included. I'll try and finish the rewrite soon. Time is the key factor.

Thanks for your comments and interest.

@Ikrids

We've just released version 2 which is more of a targeted polyfill for matchMedia. I've gone a slightly different route than my previous comments. After looking at the file size of the described version above, it was clear that the size was going in the wrong direction. Even though I was getting really tremendous speed results, I was not getting the same return in file size. So, enter the compromise. It's still fast and I was able to get some gains overall in speed. I need to create a new jsPerf page at some point.

Thought you'd be interested, hope you have a good experience with the project.

Hello
Just to tell you this project is wonderfull ! Very Good job : )
Many thanks !