...

/

Setting up the JavaScript client

Setting up the JavaScript client

Learn how to add the SignalR library for JavaScript clients.

Overview

The first (and simplest) SignalR client we'll set up is a JavaScript client. Even though we can use the SignalR client JavaScript library from a standalone application, we'll use it from our application’s pages. The client will run in the browser.

But suppose we later want to set up a JavaScript SignalR client in a different type of application (including a standalone JavaScript app). In that case, the setup process will be very similar. The code will be similar too. After all, it's the same client library.

So, let’s now go ahead and set up our client.

Adding SignalR client dependencies

There are two ways we can add SignalR library dependencies to the frontend. We can either instantiate it via npm and copy the JavaScript file into our application’s file system, which we will then reference from our front-end HTML, or we can just obtain that file from a publicly accessible URL of a content delivery network (CDN) as a direct reference in our HTML. The former method is more involved, but once completed, this file will be a part of our application forever. The latter method is much easier, but because we're dealing with a third-party URL that we have no control over, there is a very slight risk that the file might become unavailable. ...