less.js lazy sheet load

前端 未结 6 1152
天涯浪人
天涯浪人 2021-02-06 00:07

I\'m wondering if there is a way to load a single less sheet sometime after a page load. This question has an answer that explains how to reload all the sheets, but for my use-

6条回答
  •  滥情空心
    2021-02-06 00:49

    less.js has a function loadStyleSheet in it's local scope which can be used to dynamically load and parse the less styles (lazy load).

    The only problem is the function is in the closure created for defining less.js so you cannot access the function from your code.

    Maybe it can exposed by extending the api.


    Update:

    I've created a forked version of less.js @ https://github.com/livingston/less.js

    Using this version you can load any stylesheet using the method less.less.loadStyleSheet(YOUR_FILE_URL, CALLBACK)

    I've also made a pull request to the actual library, hopefully they accept my changes.

提交回复
热议问题