๐Ÿ”๏ธ

Alpine.js

Minimal framework for composing behavior directly in HTML markup

Results Summary

Performance

99%
Lighthouse Score

Bundle Size

5.0KB
Gzipped

Build Time

0s
Average

Load Time

2.1s
LCP

Complexity

68
Cyclomatic

Performance Metrics

CLS
0.0003
FCP
1361ms
LCP
2110ms
TBT
65ms

Bundle Analysis

Compression
3.2x
File Count
3
JS %
93.3%
Total Size
16.1KB

Build Info

Build Time
0s
Output Size
0.0MB
HMR Time
0ms
Dev Startup
0.0s

About the Alpine.js Weather Front App

Status

  • Lint
  • Build
  • Test

Usage Instructions

First, follow the repo setup instructions.
Then cd into ./apps/alpine/ and and use the following commands:

  • Dev Command npm run dev
  • Test Command npm run test
  • Lint Command npm run lint
  • Build Command npm run build
  • Start npm start
For troubleshooting, use npm run verify from the root of the project.

App Requirements

The purpose of this project, was to build the same identical app in every frontend framework, in order to benchmark and compare their performance. As such, each app is built to meet identical requirements, which are then verified with the test suite.

Technical Requirements

  • Binding user input and validation
  • Fetching external data asynchronously
  • Basic state management of components
  • Handling fallback views (loading, errors)
  • Using browser features (location, storage, etc)
  • Logic blocks, for iterative content and conditionals
  • Lifecycle methods (mounting, updating, unmounting)

Feature Requirements

  • ๐ŸŒฆ๏ธ Live weather conditions
  • ๐Ÿ“… 7-day weather forecast
  • ๐Ÿ” City search functionality
  • ๐Ÿ“ Geolocation support
  • ๐Ÿ’พ Persistent location storage
  • ๐Ÿ“ฑ Responsive design
  • โ™ฟ Accessible interface
  • ๐ŸŽจ Multi-theme support
  • ๐Ÿงช Fully unit tested
  • ๐ŸŒ Internationalized

Alpine.js Implementation

HTML-First Approach

Alpine.js enhances HTML directly with directives. The main index.html uses x-data="weatherApp()" to bind the weather-app.js function to the DOM.

Reactive Data Object

The weatherApp() function returns an object with reactive properties (isLoading, hasError, currentWeather) that automatically update the UI when changed.

Alpine Directives

Uses Alpine's directive system: x-show for conditional visibility, x-on:click for event handling, and x-text for content binding, making it feel like Vue but with minimal JavaScript.

No Build Step Required

Alpine works directly in the browser without compilation. Just include the script tag and start using directives - perfect for progressively enhancing existing HTML.

Vanilla JavaScript Integration

The weather logic is written in plain JavaScript functions that return reactive objects, making it easy to understand and debug without framework-specific patterns.

About Alpine.js

Real-world App

Since the weather app is very simple, and doesn't show of the full features of a framework, it may be helpful to see a more practical implementation of a Alpine.js app. So, checkout:
Who Dat Logo

Who Dat

WHOIS lookup for domain registration info

Intro to Alpine.js

About Alpine.js

Alpine is a super lightweight framework for adding interactivity directly in HTML using attributes. It feels like Tailwind but for behaviour, making it ideal for simple UI enhancements without a full build setup. Great for quick prototypes or adding sprinkles of interactivity to static sites.

My thoughts on Alpine.js

Alpine.js is like jQuery had a baby with Vue and decided to live directly in your HTML. It's refreshingly simple - you sprinkle a few x- attributes into your markup and suddenly you have reactive behavior. No build tools, no bundlers, no complexity. Just add a script tag and start building.

The approach feels intuitive once you get it. x-data sets up your reactive state, x-show handles conditional rendering, and x-for loops through arrays. Our weather app's forecast list is just <div x-for="day in forecast"> - no components, no imports, no ceremony.

What's clever is how Alpine stays out of your way. The HTML is still readable, the JavaScript is minimal, and everything degrades gracefully if Alpine doesn't load. It's progressive enhancement done right - the page works without JavaScript, but becomes interactive when it loads.

The syntax reads naturally: x-on:click="searchWeather()", x-text="temperature", x-bind:class="{'active': isExpanded}". It's declarative like Vue templates but lives right in the HTML. The reactive updates happen automatically when you modify the data.

For simple interactive websites, Alpine hits the sweet spot. You get modern reactivity without the complexity of a full framework. But for anything complex, you'll miss proper component organization and tooling. Alpine works great for my whois lookup API, because I just needed sprinkles of interactivity to update results, not a full SPA experience.

Choosing a Framework

Stack Match Stack Match

Not sure if Alpine.js is right for your project? Use Stack Match to select your preferences and get a tailored recommendation based on the benchmark data.

Stack Match Screenshot