A Require.js plugin for loading files conditionally, based on `window.matchMedia`.
A demo can be found at: http://github.e-sites.nl/require-matchmedia-plugin (or check this video)
Disclaimer: this plugin is still work in progress! Hell, it's even my first require.js plugin...so please be gentle with me.
##Syntax
requirejs([' [script-alias] ! ( [mediaquery] ) ? [path] ']);
##Getting started Include Require.js in your project if you haven't done that already. After that, make sure you include the following options in your config.
require.config({
paths: {
'mm': '/matchmedia'
},
waitSeconds: 0 // this is needed to prevent timeout errors
});
##Examples
requirejs(['mm!(screen and (max-width: 500px))?scripts/maxwidth']);
requirejs(['mm!(screen and (min-width: 1200px))?scripts/minwidth']);
requirejs(['mm!((min-width: 768px) and (max-width: 979px))?scripts/min-maxwidth.js']);
requirejs(['mm!(all and (orientation:landscape))?scripts/orientation-landscape']);
requirejs(['mm!(all and (orientation:portrait))?scripts/orientation-portrait']);
requirejs(['mm!(only screen and (min-device-pixel-ratio:2), only screen and (min-resolution: 192dpi))?scripts/retina.js']);
##Browser support
Basically all browsers that have window.matchMedia
support. If not available you can use this polyfill.
##Feedback / comments Contact me on Twitter or file an issue.
##License Copyright (C) 2014 e-sites, http://e-sites.nl/ Licensed under the MIT license.