Skip to main content

JavaScript (JS)

JavaScript is used to add interactivity to your template, including custom behaviors for blocks, sections, and pages.


Guidelines

  • NPM packages are not supported. Only local JS files included in your template can be used.
  • Include JS files in config.json under the js section to ensure they are compiled and loaded properly.
  • Scripts can be loaded async or deferred to improve page performance.

Best Practices

  1. Keep block-specific JS in separate files corresponding to each block or section.
  2. Avoid polluting the global namespace; use modules or closures where possible.
  3. Use vanilla JS or lightweight libraries already included in the template.
  4. Test scripts on all pre-defined pages, including cart, profile, and product pages, to ensure compatibility.
  5. Inline JS in your Twig templates will not work; Only rely on JS files compiled through the template system.