Skip to main content

OC Client – Installation & Setup

oc-client is the browser runtime that discovers <oc-component> tags and renders them. This page explains how to include the script, initialise it safely, and configure global settings.

Including the script

The client is itself an OC component served by every registry. Load it with a protocol-relative URL so that it automatically uses HTTP or HTTPS depending on your site:

<!-- Always served at the same version as your registry -->
<script src="//your-registry.company.com/oc-client/client.js"></script>

Best practice: Place the tag just before the closing </body>. On load the client scans the DOM and immediately calls oc.renderUnloadedComponents(). If you inject the script before your components, simply call that function yourself once the client is ready.

Safe initialisation pattern

window.oc = window.oc || {};
oc.cmd = oc.cmd || [];
oc.cmd.push(function (oc) {
// This runs after the client is fully ready
console.log("OC version:", oc.clientVersion);
});

Use the cmd queue whenever you’re not sure if the script has finished loading yet (for example in single-page apps or when dynamically injecting the client).

Configuration reference

Expose the conf object before the script tag to override defaults:

<script>
var oc = {
conf: {
debug: true,
retryInterval: 2000,
globalParameters: { userId: "123" },
},
};
</script>
<script src="//your-registry.company.com/oc-client/client.js"></script>

All options

KeyTypeDefaultDescription
debugbooleanfalseConsole logging for troubleshooting
disableLifecyclesbooleanfalseTurn off automatic lifecycle handling
disableLoaderbooleanfalseHide the loading message
globalHeadersobject | functionHeaders to include on every request
globalParametersobject{}Query-string params added to every component
loadingMessagestring""Text displayed while fetching
pollingIntervalnumber500Interval (ms) for status checks
retryIntervalnumber5000Wait time (ms) between retries
retryLimitnumber30Max retries before giving up
retrySendNumberbooleantrueAppend __ocRetry counter to requests
tagstringoc-componentCustom element name
templatesarrayES6 & common legacy templatesTemplate definitions for client-side rendering

Template configuration example

Modern components built with ES6 templates need no extra configuration. Legacy templates do require runtimes:

var oc = {
conf: {
templates: [
{
type: "oc-template-handlebars",
externals: [
{
global: "Handlebars",
url: "https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.7/handlebars.runtime.min.js",
},
],
},
],
},
};

That’s it! Continue with OC Client API for day-to-day usage or jump to Rendering Lifecycle to understand what happens in the browser.