JavaScript SDK
This fully-featured Diffusion client library can be used to interact with Diffusion Server instances from within web applications or server side Node.js based apps. It's available in minified and unminified versions, and includes TypeScript definitions out-of-the-box.
Quick Links
Download notes
- The tarball download includes modularized browser bundles, and the TypeScript definition file (refer to the Diffusion manual link for more information)
- Installing the client library via npm will include the TypeScript definitions file (see below).
Usage
Directly within a webpage
Reference the hosted version of the client library from a CDN of your choice:
<script src="https://unpkg.com/[email protected]/dist/diffusion.js"/>Use with Node.js
npm install diffusion...and within a Node.js module
var diffusion = require('diffusion');Enable message compression
To enable the optional Diffusion message compression in browser applications, a zlib implementation is required. You can use browserify to require the browserify-zlib npm module, or package/include this file:
https://download.diffusiondata.com/clients/6.12.0/js/browserify-zlib-0.2.0.js
If you are using Node.js, you don’t need to do anything to enable compression. Node.js provides zlib as a standard module.
Notes on using the client library within web application frameworks (Vue.js / React.js)
When using the client library within an ESM or CommonJS web application framework, it may be useful to polyfill the zlib (and other node API) using a third party polyfill library.
For instance, in the Vue/Vite ecosystem, the vite-plugin-node-polyfills library can be used to satisfy dependencies.
E.g. within a vite.config.ts file
import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
plugins: [
...
nodePolyfills({
include: ['process', 'zlib', 'stream', 'util'],
globals: {
Buffer: true,
},
}),
...
],
...See also the underlying Node standard polyfill library for use in the browser
Additional downloads
Additional client downloads are available for more specialised use cases, e.g. sharing Diffusion sessions across browser tabs, or optimising your web application with smaller feature-specific client bundles.
Links are provided here. Please refer to the Diffusion manual link above for more detailed guidance.
Minified and Unminified client libraries
https://download.diffusiondata.com/clients/6.12.0/js/diffusion-6.12.0.js
https://download.diffusiondata.com/clients/6.12.0/js/diffusion-unminified-6.12.0.js
Web worker bundle
https://download.diffusiondata.com/clients/6.12.0/js/diffusion-worker-6.12.0.js
Related API documentation
Modular browser bundles
The Diffusion JavaScript can also be imported in a modular way. This is useful in situations where size is critical, and tree-shaking may not be available.