Techdocs
  • Introduction
  • Implementing Nosto
    • Implement on your website
      • Manual Tagging - Essentials
        • Setting up your account
        • Adding the Nosto Script
        • Adding the Cart Tagging
        • Adding the Customer information
        • Adding the Product Tagging
          • Default Product Tagging
          • Basic Tagging
        • Adding the Category/Brand Tagging
        • Adding the Search Tagging
        • Adding the Order Tagging
        • Defining Nosto placements
        • Tagging your page types
      • Advanced Usage
        • Extending tagging with SKUs
        • Adding support for multi-currency
        • Adding support for customer group pricing
      • FAQ
    • Implement on native mobile
    • Implement on a physical store
    • Implement Search & Categories
      • Using Search Templates
        • Using Search Templates
        • Implementing Search page
        • Implementing Autocomplete
        • Implementing Category pages
        • Testing & deployment
        • FAQ
      • Using the API
        • Use the Search & Categories API
        • Implement Search results page
        • Implement Autocomplete
        • Implement Category pages
        • FAQ
      • Using the JavaScript Library
        • Implement Autocomplete using the Nosto Autocomplete library
          • Installation
          • Initialization
            • Render results
            • Submit search
          • Create Autocomplete template
          • Further reading
    • Check your setup
    • Template customization
      • Starting points
      • Product cards
      • Styling
      • Scripting
  • APIs
    • GraphQL
      • The Playground
      • Using the API
      • Testing and Debugging
      • Using Mutations
        • Updating Products
        • Updating Categories
        • Updating Identities
        • GraphQL: Onsite Sessions
        • Working with Orders
          • GraphQL: Placing Orders
          • GraphQL: Updating Order Statuses
      • Using Queries
        • Querying Products
        • Querying Identities
        • Querying Orders
        • Querying Recommendations
        • Querying Segments
        • Querying Search
        • Querying Category Merchandising Products (CM 1.0)
      • For iOS & Android
      • For Headless
    • REST
      • GDPR
        • Redacting customer data
        • Initiating data takeouts
      • Customers
        • Blacklisting Customers
        • Toggling marketing consent
      • Products
        • Updating Products
        • Discontinuing Products
        • Recrawling Products
      • Other
        • Updating Rates
    • Frontend
      • Session API
        • Terminology
        • Setting up
        • Managing Sessions
        • Handling Placements
        • Tracking Events
        • Leveraging Features
        • Record Attribution
        • Advanced Usage
          • Supporting opt-out and do-not-track
          • Using external session identifiers
          • Adding support for multi-currency
          • Adding support for customer group pricing
        • FAQ
      • JS API
        • Initializing Nosto
        • Recommendations
          • Loading Recommendations
          • Recommendation Callbacks
          • Setting up dynamic filtering
          • Sending Product-View Events
          • Sending Add to Cart-Events
        • Popups
          • Listing Popup Campaigns
          • Opening a Popup
          • Enabling & Disabling Popups
          • Popup Callbacks
        • Advanced Usage
          • Sending email addresses to Nosto
          • Manually segmenting users
          • Dynamically sending the cart content
          • Sending Customer Information
        • Record Attribution
      • Open Source
        • Nosto JS
        • Search JS
        • Nosto React
        • Web Components
          • Loading Web components
  • User Generated Content
    • UGC Techdocs
  • 3rd party data integrations
    • Shopify
    • Magento 2
    • Magento
    • BigCommerce
    • Shopware 6
    • Shopware 5
    • Prestashop
    • Salesforce
    • PHP-SDK
Powered by GitBook
On this page
  • Introduction
  • Approach #1: Using the Client Script
  • Approach #2: Using a Script Tag in Recommendation Templates

Was this helpful?

Export as PDF
  1. APIs
  2. Frontend
  3. Open Source
  4. Web Components

Loading Web components

PreviousWeb Components

Last updated 23 days ago

Was this helpful?

Introduction

Since is an open-source package, it is available through different channels:

  1. From the registry

  2. From the CDN

This gives us two ways to load the web components artifact for use in recommendation templates:

  1. Using the client script, configured through Nosto's Admin UI under Product Experience Cloud > Recommendations > Settings (recommended)

  2. Using module scripts in every recommendation template (see )

The following sections detail each approach along with its advantages and disadvantages.

Fixed Version Usage

We recommend using a fixed version instead of "latest" when loading the web components. Since the web components package is relatively new, it is expected to undergo frequent changes, and backward compatibility is not guaranteed across all new major releases.

Loading web components via Nosto's Admin UI is considered safer, as it enforces the use of a specific version.

Approach #1: Using the Client Script

A new toggle has been introduced on the Recommendation Settings page to control the loading of the web components artifact. Enabling this option requires specifying the version of the artifact to load when recommendations are rendered on store pages.

For a list of all available versions, refer to the link provided on the settings page.

Recommended Approach for Live Recommendations

If you start with our default <platform>-swatches template, it is recommended to remove the <script> tag that loads the artifact from the template before enabling web components in the settings.

Advantages

  1. Controlled directly by Nosto and loaded automatically via the client script, eliminating the need to include the artifact in every recommendation template.

  2. Updating the version is straightforward since the version is controlled via settings rather than having to change it in every recommendation template.

Disadvantages

  1. Version control is global; updating the version in settings applies it to all recommendation templates, so it cannot be set individually for each page.

  2. The web components artifact is loaded on all pages, even when a particular page does not utilize web components.

Approach #2: Using a Script Tag in Recommendation Templates

If you prefer not to enable web components globally via the recommendation settings, you can include the web components artifact directly within individual recommendation templates.

Since the web components artifact is an ES module, include it using a script tag as shown below:

<script type="module" src="https://cdn.jsdelivr.net/npm/@nosto/web-components@4.0.0/dist/main.es.bundle.js"></script>

Advantages

  1. The version of the web components artifact can be chosen individually for each template. This is beneficial when a particular version does not work in a template, and a fix for the issue is released in a newer version. Please note that the web components version is page-scoped (for example, front, product, cart, etc.), meaning only one version can be loaded per page.

  2. The web components artifact is loaded only when it is used in a recommendation template.

Disadvantages

  1. The script tag must be included in each recommendation template individually.

  2. Maintaining and upgrading the version in every recommendation template can be a tedious process.

Nosto Web Components
npm
jsDelivr
documentation
Available Web Components Versions