Install Layer

Layer is distributed as a source code package or compiled bundle, and can be easily integrated into a new app or an existing codebase with standard tooling.

The Layer Web SDK is built as a UMD module that can be loaded via CDN, NPM, or from source.

Option 1: CDN

The simplest way to load the Layer Web SDK is to add a <script> tag:

<script src='//cdn.layer.com/sdk/3.2/layer-websdk.min.js'></script>

You can also specify a patch version for stricter dependency control:

<script src='//cdn.layer.com/sdk/3.2.n/layer-websdk.min.js'></script>

n is the patch number for the desired release

All classes can then be accessed via the layer namespace:

var client = new layer.Client({
    appId: "layer:///apps/staging/YOUR-APP-ID"
});

Option 2: NPM

The Layer Web SDK is also available on NPM:

npm install layer-websdk --save

All classes can then be accessed by requireing the module:

var layer = require('layer-websdk');

var client = new layer.Client({
    appId: "layer:///apps/staging/YOUR-APP-ID"
});

Option 3: From source

Download the SDK release from Github, extract the files, and run the following commands from the extracted project folder (you’ll need to have Grunt installed:

npm install
grunt build

The build command will generate a build folder that contains client.min.js.

Other grunt commands available:

  • grunt debug: Generates build/client.debug.js which provides source-mapped files if you need to step through the Web SDK code
  • grunt docs: Generates a docs folder with the API documentation
  • grunt test: Runs the unit tests
Overview Demos