官术网_书友最值得收藏!

Installing Less on the client side

To use Less in our code, we can download it from the Less site by browsing to http://lesscss.org/#download-options-browser-downloads and then clicking on the Download Less.js v.1.7.3 button.

Save the contents of the file, displayed in the browser window as less.min.js, in a subfolder called js, under the main lessjs project folder; you will end up with something like this screenshot (this shows the files you will create later in this chapter):

In a copy of the project.html file we created at the start of this chapter, add the code as highlighted:

<!DOCType html>
<head>
  <meta charset="utf-8">
  <title>Untitled</title>
  <link rel="stylesheet/less" type="text/css" href="css/project.less">
 <script src="js/less.min.js"></script>
</head>
<body>

That's it—once this has been added, Less will compile the styles into valid CSS dynamically and render the results in the browser. The key point to note is that for Less to compile the styles correctly, the reference to the Less style sheet file must be included in your code first, before the reference to the Less library.

Tip

Can I get the source code for Less?

If you want to delve into the Less library and examine the code in more detail, then you might like to download a copy of the uncompressed version of the library, which is available at https://github.com/less/less.js/archive/master.zip.

Using a CDN

Although we could download a copy of the library, we don't need to when hosting it in a production environment. Less is available on a content delivery network hosted by CDNJS. You can instead link to this version in your code.

If you host an international site with a lot of network traffic, using a Content Delivery Network (CDN) hosted file will help ensure that the library is downloaded to a visitor's computer from a server that is geographically close to them. This helps in making the response quicker, as the browser will use a cached version on subsequent visits to the page, which saves on bandwidth. This is not recommended for development however!

Note

If you want to use a CDN link, then it can be found at http://cdnjs.cloudflare.com/ajax/libs/less.js/1.7.3/less.min.js.

主站蜘蛛池模板: 清原| 泰州市| 民丰县| 古浪县| 丰镇市| 土默特右旗| 赤壁市| 沐川县| 中卫市| 仁布县| 南充市| 东方市| 长宁县| 新宁县| 泉州市| 额尔古纳市| 永靖县| 岫岩| 新化县| 邹城市| 利辛县| 收藏| 南丹县| 交城县| 丹凤县| 沂南县| 保山市| 静安区| 富源县| 同仁县| 鄂尔多斯市| 衡南县| 谷城县| 榕江县| 灌阳县| 延长县| 龙井市| 霍山县| 湖北省| 个旧市| 乃东县|