Build modules and partials with JavaScript

Last updated:

Rather than using HubL to build modules and partials, you can use JavaScript and React instead. Then, after creating a JavaScript module or partial, you can reference it in templates using HubL. In addition to stitching server-rendered React components into the HTML generated by HubL, JavaScript modules and partials support both server-side and client-side interactivity with islands. This enables you to have more precise control over where and when JavaScript is shipped and run in the browser.

Get started with the JS Building Blocks documentation.

Benefits of building with JavaScript vs. HubL

At a high level, building with JavaScript and React comes with benefits including component composability, code reuse, broader community resources, and real access to JavaScript on the server.

Rendering React on the server means that there's less of a divide between your code that serves the initial page HTML and your interactive browser code. In contrast, creating complex and interactive pages with HubL can lead to: 

  • An increase of client-side JavaScript that slows down the page until it's all been downloaded and executed.
  • Needing to replicate or maintain UI logic across HubL and JavaScript in order to have server HTML that is immediately visible and interactive.

But by building with JavaScript, you can code complex interactive components that either share code or are directly rendered on the server. When paired with the islands model, this can enable you to more easily code web experiences that have good Core Web Vital scores (LCP, FID, CLS) even as complexity increases.

Additionally, by building on top of JavaScript and the open source framework of React, you can use the wealth of tooling, libraries, example code, and more that are available in the broader ecosystem. For example, since JavaScript modules and partials are built on top of Vite, you'll get things like ESM, TypeScript, JSX, CSS modules, and tree-shaking out of the box.

Limitations

The following features are not currently available for JavaScript modules and partials:

  • Using contact variables during local proxy.
  • Importing JavaScript modules into JavaScript partials.
  • Hot module reloading and React fast refresh.
  • Server-side API calls from inside a JavaScript module or partial.
  • Online code editing within the design manager.
  • Some HubL features, such as certain tags and filters, may not be readily available in JavaScript components.

Was this article helpful?
This form is used for documentation feedback only. Learn how to get help with HubSpot.