MODRACXKENNETH D'SILVA

← Archive & Insights

Revolutionizing Magento 2 Frontends with Hyvä Themes & Alpine.js

Hyvä Themes eliminates Magento 2's heavy RequireJS and Knockout.js dependency trees, replacing hundreds of JS requests with lightweight Alpine.js reactivity.

By Kenneth D'SilvaReading Time: 36 min readCategory: Architecture & Cloud

Hyvä Alpine.js Cart Component Code

<!-- Lightweight Hyvä Alpine.js Mini-Cart Component -->
<div x-data="initMiniCart()" @cart-updated.window="fetchCart()" class="relative">
  <button @click="open = !open" class="btn-cart">
    Cart (<span x-text="cart.summary_count">0</span>)
  </button>
</div>

<script>
function initMiniCart() {
  return {
    open: false,
    cart: {},
    fetchCart() {
      fetch('/customer/section/load/?sections=cart')
        .then(res => res.json())
        .then(data => this.cart = data.cart);
    }
  }
}
</script>

Suggested & Related Reading

Explore related engineering guides from Kenneth D'Silva: