How to wait for LESS JS to load the .less file?

1.2k views Asked by At

My webpage includes a less file instead of css. This is parsed by the less js script. My site's js script fires on dom ready and based on different dom dimensions layouts the page.

The problem is, over slow network my js file can fire before less js is able to download the less file. Since this is an unknown file type so the browser is not obliged to wait for this file to download and then fire dom ready, even when it is in the <head> section. In this scenario my js reads incorrect dimensions since no CSS rules have been applied yet.

So, my query is, how do I know when the less file have been downloaded. So that my js code can get fired after less has been downloaded and dom is ready.

1

There are 1 answers

0
MikeZ On

Check out the answer to this similar question - sounds like you just need to fire a less.refreshStyles() event which will re-compile <style> tags with type="text/less".