Skip to content

RequireJS plugin for reliably loading and waiting for css files.

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
LICENSE-GPL
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

davidpelfree/CSSLoader

 
 

Repository files navigation

CssLoader (css!) - RequireJs plugin

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.

Approach

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:

  1. Reliably understand if browser support “load” event on “link” element.
  2. 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.

Getting Started

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.

License

Licensed under the MIT, GPL licenses.

Contributing

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.

Important notes

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.

Installing grunt

This assumes you have node.js and npm installed already.

  1. Test that grunt is installed globally by running grunt --version at the command-line.
  2. If grunt isn't installed globally, run npm install -g grunt to install the latest version. You may need to run sudo npm install -g grunt.
  3. From the root directory of this project, run npm install to install the project's dependencies.

Installing PhantomJS

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.

Note that the phantomjs executable needs to be in the system PATH for grunt to see it.

About

RequireJS plugin for reliably loading and waiting for css files.

Resources

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
LICENSE-GPL
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published