Note that there are some explanatory texts on larger screens.

plurals
  1. POless.js lazy sheet load
    primarykey
    data
    text
    <p>I'm wondering if there is a way to load a single <a href="https://github.com/cloudhead/less.js" rel="nofollow noreferrer">less</a> sheet sometime after a page load. <a href="https://stackoverflow.com/questions/3175013/load-less-js-rules-dynamically">This question</a> has an answer that explains how to reload all the sheets, but for my use-case existing sheets never have dependencies on newly loaded sheets, and it would be good to just add the sheet lazily. I'm thinking something like</p> <pre><code>less.sheets.push(mySheet); less.loadStyleSheet(mySheet); </code></pre> <p>might represent a possible API? Cheers,</p> <p>Colin</p> <p>UPDATE 3rd Dec 2010:</p> <p>I've tried out Livingston Samuel's fix of the less.js codebase, and while it does work, it doesn't appear to recognise definitions in already loaded stylesheets. Here are my sample files </p> <p>a. index.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Simple&lt;/title&gt; &lt;link rel="stylesheet/less" href="/static/less/style.less" id="abc123"/&gt; &lt;script src="/static/js/less-1.0.40.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;div&gt;Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.&lt;/div&gt; &lt;/div&gt; &lt;div id="abc"&gt;&lt;div&gt;Bingo&lt;/div&gt;&lt;/div&gt; &lt;/body&gt; &lt;script&gt; console.log("loading new sheet"); less.loadStyleSheet("/static/less/style2.less", function() { console.log("Loaded!"); }); console.log("called"); &lt;/script&gt; &lt;/html&gt; </code></pre> <p>b. style.less</p> <pre><code>@primary_color: green; .rounded(@radius: 5px) { -moz-border-radius: @radius; -webkit-border-radius: @radius; border-radius: @radius; } #container { background: @primary_color; .rounded(5px); div { color: red; } } </code></pre> <p>c. style2.less</p> <pre><code>#abc { background: @primary_color; .rounded(10px); div { margin: 2px; color: blue; } } </code></pre> <p>So the second stylesheet does load lazily, but it has the following parsing error in style2.less</p> <p>".rounded is undefined"</p> <p>.rounded is defined style.less, and since I haven't unloaded that sheet, I was thinking it should be still available to the compiler in the current environment.</p> <p>To put it another way, we don't want to start fresh, or to unload existing definitions, but build on the styles already loaded. Thanks,</p> <p>Colin</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload