htmx
htmx
Implements AJAX and WebSocket through HTML attributes. Minimizes JavaScript.
htmx
Implements AJAX and WebSocket through HTML attributes. Minimizes JavaScript.
htmx is a library that lets you implement AJAX, WebSocket, and SSE using only HTML attributes. It is called an "extension of HTML" because you can build dynamic web pages without writing JavaScript directly.
It fits well with the traditional approach of returning HTML from the server, so it works well with template-based frameworks such as Django and Rails.
<!-- CDN์ผ๋ก htmx ๋ก๋ -->
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<!-- ํด๋ฆญ ์ GET ์์ฒญ, ์๋ต์ #result์ ์ฝ์
-->
<button hx-get="/api/greeting" hx-target="#result">์ธ์ฌํ๊ธฐ</button>
<div id="result"></div>
<!-- ํผ ์ ์ถ (POST) -->
<form hx-post="/api/users" hx-swap="outerHTML">
<input name="name" placeholder="์ด๋ฆ">
<button>๋ฑ๋ก</button>
</form>
<!-- ๋ฌดํ ์คํฌ๋กค -->
<div hx-get="/api/items?page=2"
hx-trigger="revealed"
hx-swap="afterend">
๋ก๋ฉ ์ค...
</div>
Backend developer
"Can I build a dynamic UI without React? It's just a simple admin page, so I don't need a full SPA."
Senior
"Try htmx. Just add HTML attributes and AJAX is handled. Just return an HTML fragment from the server and you're done. It goes perfectly with Django templates."
Limits in complex state management: If the client-side state is complex, React or similar is more suitable.
SEO: Dynamically loaded content is not in the initial HTML, which can be disadvantageous for SEO.