Skip to content

Vanilla JavaScript

Don’t want to use a framework? JamComments works with plain JavaScript too. See a live demo.

Even without server-side rendering, this approach has advantages over other comment widgets:

  • Minimal setup (~10 lines of code)
  • No custom CSS to write
  • Small footprint: ~2.6kb (gzipped) JavaScript + ~3.6kb (gzipped) HTML loaded on demand

Option 1: npm

Terminal window
npm install @jam-comments/client

Option 2: CDN

<script src="https://unpkg.com/@jam-comments/client"></script>

With ES modules:

import { initialize } from "@jam-comments/client";
initialize("#comments-container", {
path: window.location.pathname,
apiKey: "your-api-key",
domain: "your-site.com",
environment: "production",
});

With CDN:

<script src="https://unpkg.com/@jam-comments/client"></script>
<script>
JamComments.initialize("#comments-container", {
path: window.location.pathname,
apiKey: "your-api-key",
domain: "your-site.com",
environment: "production",
});
</script>

The first argument is a CSS selector (like "#comments-container") or a direct reference to an HTML element (like document.getElementById('comments-container')). The comment form and any existing comments will be rendered inside this element.

initialize() returns a Promise that resolves after the form is ready:

initialize("#comments", {
path: window.location.pathname,
apiKey: "your-api-key",
domain: "your-site.com",
}).then((element) => {
// Form is now rendered and ready
element.classList.add('is-loaded');
});

The promise resolves after the first repaint, so it’s safe to use for CSS animations:

OptionRequired?Description
pathYesThe page path for loading and saving comments
domainYesYour site’s domain (from account settings)
apiKeyYesYour API key (from account settings)
environmentYes”production” or “development”
dateFormatNoDate format using PHP syntax. Default: “m/d/Y”

Loading comments client-side has trade-offs:

  • Performance: The comment form loads after your page, which may cause a slight layout shift
  • SEO: Search engines may not see the comments as easily as server-rendered content

For better performance and SEO, use a server-side integration if possible. The vanilla client is best for sites where you can’t run server-side code.