Load less.js rules dynamically

前端 未结 4 954
傲寒
傲寒 2020-11-27 14:56

I\'m looking at using less.js (looks great), but our site requires that some styles be loaded dynamically after initial page load. It seems, however, that all LESS styleshe

4条回答
  •  北海茫月
    2020-11-27 15:44

    thanks for asking this question – it helped me a lot. I’m just updating the topic in order to show how I did to dynamically add a CSS file.

    I used the last version of LESS (1.3.3).

    var stylesheetFile = 'file.css';
    var link  = document.createElement('link');
    link.rel  = "stylesheet";
    link.type = "text/less";
    link.href = stylesheetFile;
    less.sheets.push(link);
    
    less.refresh();
    

提交回复
热议问题