Book Image

Getting Started with Knockout.js for .NET Developers

By : Andrey Ankshin
Book Image

Getting Started with Knockout.js for .NET Developers

By: Andrey Ankshin

Overview of this book

Table of Contents (14 chapters)
Getting Started with Knockout.js for .NET Developers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing Knockout.js


There are a few ways to install Knockout.js, and each method is outlined here. Generally, you want to use the first or second method, but the third and fourth methods can be useful in some special cases.

Method 1 – official site

You can manually download Knockout.js from the official site http://knockoutjs.com/. You can see the screen of the main page in the following screenshot:

After downloading, you can add a reference to Knockout.js from your HTML page using a <script> tag. For example, if the library was downloaded to the root directory of your application, then you can use the following line of code:

<script type='text/javascript' src='knockout-3.1.0.js'></script>

You should use the actual version of the library instead of version 3.1.0 (released in March 2014) in the preceding example line of code. Hereafter, we will use version 3.1.0 (it is the current version at the time of writing this book), but because of backward compatibility all examples should work with future Knockout.js versions very well.

Also, you can download the debug build for learning purposes (from the download page at http://knockoutjs.com/downloads/index.html). It helps you to understand how Knockout.js works. Don't use it for real production applications.

Method 2 – NuGet

If you develop a website with .NET, you can install it via NuGet (https://www.nuget.org/packages/knockoutjs). Just run the following command in the Package Manager Console:

Install-Package knockoutjs

Method 3 – CDNs

Content distribution network (CDN) is a large system for delivery or distribution of some content to end users' servers. You can use third-party CDNs for reference Knockout.js. Examples of CDNs can be found at http://cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js and http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.0.0.js.

Note that not all CDNs support the latest actual version of the library. The best way is to use a local library version on your server, but the CDNs method can be very useful for quick single-page solutions.

Method 4 – GitHub

Full sources of the library are placed on GitHub at https://github.com/knockout/knockout. You can build the latest Knockout.js version from source by yourself by executing the following steps:

  1. Clone the repo from GitHub. Make sure that you have Git installed on your local machine:

    git clone https://github.com/knockout/knockout.git
    cd knockout
    
  2. Acquire build dependencies. Make sure that you have Node.js installed on your local machine:

    npm install -g grunt-cli
    npm install
    
  3. Run the build tool:

    Grunt
    

Done! Now you can find the built files in the build/output/ directory.