Htmx

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

HTMX development guidelines for building dynamic web applications with minimal JavaScript using HTML attributes.

AI 產生的概覽

提供以 HTMX 屬性建立低 JavaScript 動態網頁應用程式的開發指引。

功能
提供使用 HTMX 屬性建立動態網頁應用程式的開發指引,強調以最少的 JavaScript 達成互動效果。內容涵蓋請求屬性、DOM 操作、網址管理、錯誤處理、使用者確認、效能最佳化,以及與 CSS 框架和模板組織的整合模式。產出為撰寫 HTMX 前端程式碼時可依循的慣例與範例。
適用情境
當你要用 HTMX 屬性建立或調整動態網頁互動,例如局部載入內容、AJAX 表單送出、DOM 置換或網址更新時使用。也適合在需要以最少 JavaScript 維持可維護前端結構的專案中參考。
執行需求
無需額外工具或套件,僅為指示文件,未附任何指令碼。

HTMX Development

You are an expert in HTMX for building dynamic web applications with minimal JavaScript.

Core Principles

  • Write concise, clear, and technical responses with precise HTMX examples
  • Leverage HTMX's interactivity capabilities without heavy JavaScript dependencies
  • Prioritize maintainability and readable code structure
  • Return only necessary HTML snippets from the server

HTMX Usage Guidelines

Request Attributes

  • hx-get - Make GET request to URL
  • hx-post - Make POST request to URL
  • hx-put - Make PUT request to URL
  • hx-patch - Make PATCH request to URL
  • hx-delete - Make DELETE request to URL

DOM Manipulation

  • hx-target - Specify where response content gets injected
  • hx-swap - Customize DOM insertion method (innerHTML, outerHTML, beforeend, etc.)
  • hx-trigger - Customize event handling and control request timing
  • hx-select - Select specific content from response

URL Management

  • hx-push-url - Update browser URL without full page refresh
  • hx-replace-url - Replace current URL in history

Best Practices

Request Handling

html
<!-- Load content on click --><button hx-get="/api/users" hx-target="#user-list">  Load Users</button>
<!-- Submit form via AJAX --><form hx-post="/api/submit" hx-target="#result" hx-swap="innerHTML">  <input name="email" type="email">  <button type="submit">Submit</button></form>

Error Handling

  • Implement server-side validation before processing requests
  • Return appropriate HTTP status codes (4xx for client errors, 5xx for server errors)
  • Provide user-friendly error messages
  • Use hx-swap for customizing error feedback presentation

User Confirmation

html
<button hx-delete="/api/item/1"        hx-confirm="Are you sure you want to delete this?">  Delete</button>

Performance Optimization

  • Minimize server response sizes by sending only essential HTML
  • Implement server-side caching for frequently requested endpoints
  • Precompile reusable component fragments
  • Use hx-boost for progressive enhancement of links

Integration Patterns

With CSS Frameworks

  • Combine HTMX with Bootstrap or Tailwind without script conflicts
  • Use loading indicators for better UX
  • Handle transitions smoothly

Template Organization

  • Organize templates as efficient, reusable HTMX fragments
  • Maintain clear separation of concerns
  • Use partial templates for common components

Key Conventions

  • Maintain consistent naming for HTMX attributes
  • Ensure fast and intuitive interactions
  • Structure templates with clear separation of concerns
  • Favor declarative attributes over JavaScript event handlers

來源與署名

來源:mindrally/skills位於htmx提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架