Get started with postal.js CDN

MIT licensed

Postal.js is a publish-subscribe messaging library for the browser.

Tags:
  • pub/sub
  • pub
  • sub
  • messaging
  • message
  • bus
  • event
  • mediator
  • broker
  • envelope

Stable version

Copied!

How to start using postal.js CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with postal.js CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/postal.js/2.0.6/postal.min.js"></script>
</head>
<body>
  <script>
    // Initialize Postal.js
    const bus = new Postal();

    // Define a channel
    bus.channel('myChannel');

    // Publish a message on the channel
    bus.channel('myChannel').publish({ type: 'myMessageType', data: 'Hello, Postal.js!' });

    // Subscribe to the channel and handle messages
    bus.channel('myChannel').subscribe({
      'myMessageType': function(message) {
        console.log('Received message:', message.data);
      }
    });
  </script>
</body>
</html>
Copied!
Copied!

All versions