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

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.

主站蜘蛛池模板: 泗阳县| 临漳县| 皋兰县| 黄冈市| 抚松县| 全椒县| 松江区| 仙桃市| 乌苏市| 平湖市| 五原县| 棋牌| 武汉市| 克东县| 西充县| 启东市| 安陆市| 南部县| 营口市| 赤峰市| 水富县| 宁武县| 安丘市| 叶城县| 吕梁市| 太白县| 台南县| 井陉县| 济源市| 中卫市| 南和县| 呼伦贝尔市| 固镇县| 英山县| 湘潭市| 苗栗市| 随州市| 汉阴县| 新晃| 霞浦县| 米脂县|