Mobile Group Chat with One Line of JavaScript

0 MIN READ • Jun 5, 2014

Waving Hand

Good News! We've launched an all new Chat Resource Center.

We recommend checking out our new Chat Resource Center, which includes overviews, tutorials, and design patterns for building and deploying mobile and web chat.

Take me to the Chat Resource Center →

One of our first and most popular blog posts is Chat in 10 Lines of Code. In my constant quest to outperform PubNub founder and CTO Stephen Blum, I decided to challenge myself to create a mobile group chat demo that was responsive and ready for mobile in just one line of JavaScript.

mobile group chat

Yes, that's right…with one line of code you'll get a mobile group chat app that looks like this:

Today, I’m happy to announce the release of the PubStrapChat jQuery plugin. With this library you can add mobile group chat to your site, mobile or otherwise, with a single line of javascript:

one.js
$('#target').pubstrapchat();

The chat box drops right into any div on your page. It's fully responsive and will look great on any mobile site with Bootstrap. Or, you can ditch Bootstrap and style it yourself.

You’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Portal.

All the code you need to get started and an example is below:

See the Pen PubStrapChat by Ian Jennings (@ianjennings) on CodePen.

quickstart.html
<script src="http://cdn.pubnub.com/pubnub.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.rawgit.com/pubnub/pubstrap-chat/master/lib/pubstrap-chat.js"></script>
<div id="target">
</div>
<script type="text/javascript">
$(function() {
  $('#target').pubstrapchat();
});
</script>

The PubStrapChat plugin can be extended to use your own PubNub API keys and even your own user authentication system. You can configure the plugin by using an options object.

options.js
var options = {
  publish_key: 'demo',
  subscribe_key: 'demo',
  channel: 'pubstrapchat',
  submit_text: 'Send',
  height: '200px'
};

$('#target').pubstrapchat(options);

Check out the documentation to get it working with your custom user system. You can even set it up to use third party authentication systems like Facebook.

Latest blog posts

Real-Time
Oct 25, 2026

PubNub DataSync vs. real-time databases: Where your app's live state belongs

When to keep live app state in PubNub DataSync, when you still need a real-time database, and how a marathon app splits its data between them.
Dawid Urbas
Dawid Urbas
AI
Oct 7, 2026

Why MCP Alone Isn’t Enough for AI-Assisted Real-Time Development

Discover why Model Context Protocol (MCP) alone isn't enough for building production-ready real-time apps, and how combining MCP with engineering guidance (PubNub Skills) ensures robust architecture.
Ginni Kakkar
Ginni Kakkar
Sports Media Engagement
Oct 1, 2026

The ultimate guide to fandom engagement in 2026

Learn the value of fandom engagement platforms and how brands monetize direct-to-consumer proximity, real-time messaging, and tiered subscriptions.
Daryl Pereira
Daryl Pereira