To begin, add the SDK script to the
head of your HTML:
<script src="https://cdn.commoninja.com/sdk/latest/commonninja.js" defer></script>
This script introduces a
CommonNinja object to the global (
window) scope of your application or webpage.
Automatic Widget Discovery
Once loaded, the SDK operates automatically to find and initialize any Common Ninja widgets present on your page. There's no need for further action on your part for the widgets to function as expected.
For more fine-grained control, the
CommonNinja object exposes several methods:
CommonNinja.reload(widgetId): This method triggers a reload of your widgets. Provide a specific
widgetIdto reload that widget alone, or call without parameters to reload all widgets on the page.
CommonNinja.destroy(widgetId): Use this method to remove a widget from the page. Provide a specific
widgetIdto remove that widget alone, or call without parameters to remove all widgets on the page.
CommonNinja.init(): This method reinitializes all the widgets on the page. It's useful when dynamic changes to the page might add or remove widgets.
Disabling CDN Caching
We use a CDN to ensure fast loading times for our widgets. However, if you want to work with the latest data of the widgets on your page and disable the CDN cache, add the following global variable to the window level:
window.cnDisableCache = true;
Alternatively, you can add this setting as a query parameter on the page level:
This change ensures that the SDK always loads the most recent version of each widget, directly from our servers.