Alpine.js
v3.17.5Lightweight framework for adding reactive behaviour directly in your HTML markup.
Quick start
Add this tag to your page. Place it in the <head>. The defer attribute makes sure it runs after the page has loaded.
HTML
<script defer src="https://jscdns.net/libs/alpinejs/3.17.5/cdn.min.js"
integrity="sha384-FYLKjwG3aohNhNZoVG8sY/5ntunm+MqylL90Q+rT3OM7AwV9/BKFjk/RjoIpIgsI" crossorigin="anonymous"></script>Files
| File | Size | Copy |
|---|---|---|
| cdn.min.jsScript | 54.6 KB | |
| module.esm.min.jsES module | 54.6 KB |
Usage
Complete example
A minimal page that loads Alpine.js and uses it. Copy it into a file and open it in your browser.
example.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script defer src="https://jscdns.net/libs/alpinejs/3.17.5/cdn.min.js"
integrity="sha384-FYLKjwG3aohNhNZoVG8sY/5ntunm+MqylL90Q+rT3OM7AwV9/BKFjk/RjoIpIgsI" crossorigin="anonymous"></script>
</head>
<body>
<div x-data="{ open: false, count: 0 }">
<button @click="count++">Clicked <span x-text="count"></span> times</button>
<button @click="open = !open">Toggle panel</button>
<div x-show="open">This panel is controlled by Alpine.</div>
</div>
</body>
</html>Using the ES module build
If your page already uses <script type="module">, you can import the module build directly instead of relying on a global variable.
module.html
<script type="module">
import Alpine from 'https://jscdns.net/libs/alpinejs/3.17.5/module.esm.min.js';
window.Alpine = Alpine;
Alpine.start();
</script>Good to know. Load cdn.min.js with the defer attribute so Alpine initialises after the page has been parsed. Alpine starts itself automatically.