#NOTE
A better plugin with all the cases handled, good support for r.js and less is available at https://github.com/guybedford/require-css. You should better have look at that if you are looking at this.
A RequireJS plugin which loads and waits for css files. Uses the standard load event on browsers which support it (IE, Firefox 9+, Opera) and uses a script tags load & error events as a workaround (Chrome, Safari, Firefox < 9). Detection of link load event support is done using a link element with a data url, which fires onload immediately when supported.
Only caveats in browsers not supporting the native link load event are that there will be JavaScript parse errors (since browsers try to interpret the dummy script tags used for load event detection) and there will be no RequireJS error message when a stylesheet could not be found/loaded. Also beware of IE's 31 style sheets limit (fixed in IE 10).
- Firefox 1.0.1+
- Safari 3.2+
- Mobile Safari 4 (iOS 3.2)+
- Chrome 1+
- Opera 9.5+
- IE 6+
- Media-Query support
- r.js optimizer support
- Workaround for missing link load event - Daniel Buchner, backalleycoder.com
- Inspiration to build this plugin - John Hann, unscriptable.com
- Independently developed some of the same techniques and describes them in details - Julian Aubourg, jaubourg.net