Skip to content

Instantly share code, notes, and snippets.

@royts
Last active December 18, 2015 20:59
Show Gist options
  • Save royts/5843967 to your computer and use it in GitHub Desktop.
Save royts/5843967 to your computer and use it in GitHub Desktop.
AngularJS CSS lazy loading - first version. Ream more here: http://www.royts.com/2013/06/css-lazy-loading-in-angularjs-app.html
angular.module('cssLoadingService', []).factory("CssLoadingService", function () {
return {
loadCss: function (url) {
if (document.createStyleSheet) {
document.createStyleSheet(url); //IE
} else {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url;
document.getElementsByTagName("head")[0].appendChild(link);
}
}
};
});
function SomeController(CssLoadingService) {
CssLoadingService.loadCss("style.css");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment