Would it be a bad practice to use less.js in a pro

2019-02-13 15:30发布

This script basically turns .less code into .css code. I think it will only cause problems if the user has javascript turned off, but do many people do that?

Any suggestions?

标签: less
4条回答
Root(大扎)
2楼-- · 2019-02-13 16:00

It really depends on what you're building and who your target audience is. Modern browsers that support HTML5 will cache the generated CSS the first time it loads so if the majority of your visitors will be using modern browsers it's pretty safe.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-13 16:00

Other options is making your own less compiler in server and then you can "play" with cache times css results.

You can check libraries as LessPHP in order to do that.

查看更多
唯我独甜
4楼-- · 2019-02-13 16:02

Many people do (I don't have exact numbers, but IIRC less than 4%), but you are under no obligation to provide functionality without javascript. Many of the more advanced sites today do not. It depends on what you are serving and who your audience is.

Of course it's great to provide this functionality if you can. I would be more concerned about the effect less.js will have on your site's load time. If you can't load the CSS until after the javascript, you have to delay rendering until the javascript runs, in order to avoid an unseemly transition from unstyled to styled.

You can have your .less files auto-compile into CSS whenever they are changed by using tools that watch directories.

查看更多
forever°为你锁心
5楼-- · 2019-02-13 16:05

Just compile the .less into .css before putting it into a production environment. That way it will still display to those without JS enabled, and won't suffer the issues @Plynx mentioned.

As for compiling, there are some real-time compilers out there, specifically:

Both compile .less to .css on file save, which is awesome, and makes LESS easier to use!

查看更多
登录 后发表回答