RequireJs plugin for reliably loading and waiting for css files.
##Inspiration Need for well tested and reliable plugin for loading css resources using RequireJs.
The main issue with loading and waiting for css files, is actually not “loading” (I found only IE 31 stylesheet limit problematic,described below) but “waiting” when stylesheet is downloaded and applied on DOM. Described here and here.
After looking on existing plugins and approaches I came to conclusion that in order to address “waiting” issue the bellow things needs to be addressed first:
- Reliably understand if browser support “load” event on “link” element.
- Reliably understand if style sheet is applied on DOM when native “load” event doesn't provided by browser.
Plugin logic also contains the workaround for IE 31 stylesheet limit.
Because of lot of caveats in different browsers each approach used in plugin is tested thoroughly. All the tests done using Qunit and can be found here.
Download the production version or the development version.
##Compatability Tested on : IE7,IE8,IE9, Firebox: 10.0.2, Chrome:21.0, Opera:12.02, Safari:5.17
##Credits Understanding if event is supported on element.
- Worth to add that I first came to that approach when walking through the jQuery code.
Get identification when css is applied to DOM.
##TODO: Check that stylesheet not only applied to DOM but also that rules are applied on stylesheets loaded from another domain.
Handle the css files with @import directives.
Support for Requirejs optimizer.
Licensed under the MIT, GPL licenses.
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Please don't edit files in the dist
subdirectory as they are generated via grunt. You'll find source code in the src
subdirectory!
While grunt can run the included unit tests via PhantomJS, this shouldn't be considered a substitute for the real thing. Please be sure to test the test/*.html
unit test file(s) in actual browsers.
This assumes you have node.js and npm installed already.
- Test that grunt is installed globally by running
grunt --version
at the command-line. - If grunt isn't installed globally, run
npm install -g grunt
to install the latest version. You may need to runsudo npm install -g grunt
. - From the root directory of this project, run
npm install
to install the project's dependencies.
In order for the qunit task to work properly, PhantomJS must be installed and in the system PATH (if you can run "phantomjs" at the command line, this task should work).
Unfortunately, PhantomJS cannot be installed automatically via npm or grunt, so you need to install it yourself. There are a number of ways to install PhantomJS.
- PhantomJS and Mac OS X
- PhantomJS Installation (PhantomJS wiki)
Note that the phantomjs
executable needs to be in the system PATH
for grunt to see it.