JavaScript ES modules

Basic Example with HTML/CSS/JS

This contrived example demonstrates how to show a simple recommendation using the ESM version of the library. Instead of loading the library as a <script> tag, the importstatement is used.

The following code demonstrates synchronous imports. Dynamic imports may also be used.

<!DOCTYPE html>

<head>
  <link rel="stylesheet" type="text/css" href="index.css">
</head>

<body>
  <h4>Headless Recommendations</h4>
  <p>Using ES modules</p>

  <script type="module" src="index.js"></script>
</body>
body {
  font-family: Arial, Helvetica, sans-serif;
}

.item {
  border: 1px solid #ccc;
  padding: 0 10px;
  margin: 5px;
  width: 200px;
  height: 300px;
  display: inline-block;
  vertical-align: top;
}

.item>a {
  text-decoration: none;
}

.item>a>img {
  width: 100%;
  max-width: 200px;
}

Last updated

Was this helpful?