I would like to add a theme support to my single page application. The requirement is that the theme change must be done locally by javascript (no server calls) to be used in offline mode. I use angularjs, so html will be changed in the router.
The only problem that I have, is how to treat css. Is there any js library to help me load css files? Are there any problems involved in that?
EDIT: I have found the following library https://github.com/rgrove/lazyload/ which should do the job of loading css files. The only downside of the library is that the last update of the library is more than one year ago. A more actively developed library would be appreciated.
styleelements can be added and removed in JavaScript. Simply create the element and add it to the page to apply the rules therein, and remove the element to remove its rules. You can do the same withlinkelements referring to external stylesheets, but if you want to be sure to work in offline mode and if the sheet may not have been cached,styleelements with inline rules might work better.Here’s an example using a
styleelement:Live Copy | Source
Using a
linkwould be even easier, because you don’t have to deal with browser differences around where the style text goes.