The JavaScript Chat SDK
Our JavaScript SDK allows you to easily add chat to your app. You can install the SDK into your site in two ways:
Put the code below in your app's <head>
or at the very end of the <body>
.
HTML<script>(function(t,a,l,k,j,s){s=a.createElement('script');s.async=1;s.src="https://cdn.talkjs.com/talk.js";a.head.appendChild(s);k=t.Promise;t.Talk={v:2,ready:{then:function(f){if(k)return new k(function(r,e){l.push([f,r,e])});l.push([f])},catch:function(){return k&&new k()},c:l}};})(window,document,[]);</script>
Make sure you include it on every page of your app, so that TalkJS's notification features work correctly.
If you use a bundler for your client-side JavaScript, such as Webpack, Browserify or Parcel, you can use NPM to import TalkJS into your app:
npm install talkjs --save# or, if you use yarnyarn add talkjs
In your code, in place that is loaded on every page, do:
const Talk = require('talkjs');// or, if you use ES6 or TypeScriptimport Talk from 'talkjs';
Our NPM package ships with TypeScript type definitions, which means you'll get auto-completion on certain editors (such as Visual Studio Code or Atom):
We've done our best to keep the core TalkJS SDK exceptionally small,
so that your page load times are not impacted.
talk.js
is only ~23kB gzipped and it is served from our global CDN to ensure fast load times across the globe.
Also, talk.js
is loaded asynchronously, so that your page can display before talk.js
has loaded.