๐ŸŒ Web Development

htmx

htmx

Implements AJAX and WebSocket through HTML attributes. Minimizes JavaScript.

Detailed Explanation

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.

Code Example

<!-- 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>

Practical Conversation Example

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."

Cautions

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.

Related Terms

Learn More