1. Home
  2. Htmx
  3. Basic
  4. đŸŽ¯ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ ā§§: HTMX āĻāϰ āĻĒāϰāĻŋāϚāϝāĻŧ āĻ“ āϏ⧇āϟāφāĻĒ

đŸŽ¯ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ ā§§: HTMX āĻāϰ āĻĒāϰāĻŋāϚāϝāĻŧ āĻ“ āϏ⧇āϟāφāĻĒ

📚 āĻāχ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ⧇ āϝāĻž āĻļāĻŋāĻ–āĻŦ⧇āύ:

  • ✅ HTMX āĻ•āĻŋ āĻāĻŦāĻ‚ āϕ⧇āύ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻŦ⧇āύ
  • ✅ Traditional JavaScript vs HTMX āĻāϰ āĻĒāĻžāĻ°ā§āĻĨāĻ•ā§āϝ
  • ✅ HTMX CDN āĻĻāĻŋāϝāĻŧ⧇ āϏ⧇āϟāφāĻĒ āĻ•āϰāĻžāϰ āĻĒāĻĻā§āϧāϤāĻŋ
  • ✅ Live Server āĻāϰ āϗ⧁āϰ⧁āĻ¤ā§āĻŦ āĻāĻŦāĻ‚ āϏ⧇āϟāφāĻĒ
  • ✅ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒā§āϞāĻŋāϕ⧇āĻļāύ āϤ⧈āϰāĻŋ
  • ✅ Browser Developer Tools āĻĻāĻŋāϝāĻŧ⧇ HTMX āĻĄāĻŋāĻŦāĻžāĻ—āĻŋāĻ‚

âąī¸ āϏāĻŽāϝāĻŧ: ā§Šā§Ļ-ā§Ēā§Ģ āĻŽāĻŋāύāĻŋāϟ | 📋 āĻĒā§āϰāϝāĻŧā§‹āϜāύ: HTML āĻāϰ basic āĻœā§āĻžāĻžāύ

âš ī¸ āĻ…āĻ¤ā§āϝāĻ¨ā§āϤ āϗ⧁āϰ⧁āĻ¤ā§āĻŦāĻĒā§‚āĻ°ā§āĻŖ: Live Server āĻĒā§āϰāϝāĻŧā§‹āϜāύ!

HTMX āĻļ⧁āϧ⧁āĻŽāĻžāĻ¤ā§āϰ Live Server āĻ āĻ•āĻžāϜ āĻ•āϰ⧇! File:// protocol āĻ āĻ•āĻžāϜ āĻ•āϰāĻŦ⧇ āύāĻžāĨ¤

đŸ› ī¸ Live Server āϏ⧇āϟāφāĻĒ āĻ•āϰāĻžāϰ āωāĻĒāĻžāϝāĻŧ:

  • VS Code: “Live Server” extension install āĻ•āϰ⧁āύ
  • Python: python -m http.server 8000
  • Node.js: npx http-server
  • PHP: php -S localhost:8000

āϕ⧇āύ āĻĒā§āϰāϝāĻŧā§‹āϜāύ: HTMX AJAX requests āĻĒāĻžāĻ āĻžāϝāĻŧ, āϝāĻž CORS policy āĻāϰ āĻ•āĻžāϰāϪ⧇ local files āĻ āĻ•āĻžāϜ āĻ•āϰ⧇ āύāĻžāĨ¤


🤔 HTMX āĻ•āĻŋ āĻāĻŦāĻ‚ āϕ⧇āύ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻŦ⧇āύ?

📖 HTMX āĻāϰ āϏāĻ‚āĻœā§āĻžāĻž:

HTMX āĻšāϞ āĻāĻ•āϟāĻŋ JavaScript library āϝāĻž HTML attributes āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇ modern web features āĻĒā§āϰāĻĻāĻžāύ āĻ•āϰ⧇āĨ¤ āĻāϟāĻŋ āφāĻĒāύāĻžāϕ⧇ āϜāϟāĻŋāϞ JavaScript āϕ⧋āĻĄ āύāĻž āϞāĻŋāϖ⧇āχ dynamic web applications āϤ⧈āϰāĻŋ āĻ•āϰāϤ⧇ āϏāĻžāĻšāĻžāĻ¯ā§āϝ āĻ•āϰ⧇āĨ¤

đŸŽ¯ HTMX āĻĻāĻŋāϝāĻŧ⧇ āϝāĻž āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ:

  • ✅ AJAX Requests: Page reload āĻ›āĻžāĻĄāĻŧāĻžāχ data load āĻ•āϰāĻž
  • ✅ CSS Transitions: Smooth animations āĻāĻŦāĻ‚ effects
  • ✅ WebSockets: Real-time communication
  • ✅ Server Sent Events: Live data updates
  • ✅ History Management: Browser back/forward button support

🌟 HTMX āĻāϰ āĻŽā§‚āϞ āϏ⧁āĻŦāĻŋāϧāĻžāϏāĻŽā§‚āĻš:

1ī¸âƒŖ āĻ…āĻ¤ā§āϝāĻ¨ā§āϤ āϏāĻšāϜ āĻļ⧇āĻ–āĻž:

HTML āϜāĻžāύāϞ⧇āχ HTMX āĻļāĻŋāĻ–āϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύāĨ¤ āϕ⧋āύ complex JavaScript framework āĻļ⧇āĻ–āĻžāϰ āĻĒā§āϰāϝāĻŧā§‹āϜāύ āύ⧇āχāĨ¤

2ī¸âƒŖ āĻ•āĻŽ āϕ⧋āĻĄ āϞāĻŋāĻ–āϤ⧇ āĻšāϝāĻŧ:

Traditional JavaScript āĻāϰ āϤ⧁āϞāύāĻžāϝāĻŧ ā§Žā§Ļ% āĻ•āĻŽ āϕ⧋āĻĄ āϞāĻŋāϖ⧇ āĻāĻ•āχ āĻ•āĻžāϜ āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύāĨ¤

3ī¸âƒŖ āĻĻā§āϰ⧁āϤ Development:

āĻ•āĻŽ āϏāĻŽāϝāĻŧ⧇ āĻŦ⧇āĻļāĻŋ functionality implement āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύāĨ¤

4ī¸âƒŖ SEO Friendly:

Server-side rendering support āĻ•āϰ⧇, āϤāĻžāχ search engines āϏāĻšāĻœā§‡āχ index āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āĨ¤

5ī¸âƒŖ Progressive Enhancement:

JavaScript disable āĻĨāĻžāĻ•āϞ⧇āĻ“ basic functionality āĻ•āĻžāϜ āĻ•āϰ⧇āĨ¤

6ī¸âƒŖ Lightweight:

āĻŽāĻžāĻ¤ā§āϰ ā§§ā§ĻKB size, āϝāĻž āĻ…āĻ¨ā§āϝāĻžāĻ¨ā§āϝ framework āĻāϰ āϤ⧁āϞāύāĻžāϝāĻŧ āĻ…āύ⧇āĻ• āϛ⧋āϟāĨ¤


âš–ī¸ Traditional JavaScript vs HTMX āĻāϰ āĻĒāĻžāĻ°ā§āĻĨāĻ•ā§āϝ

📊 āĻŦāĻŋāĻ¸ā§āϤāĻžāϰāĻŋāϤ āϤ⧁āϞāύāĻž:

🔹 AJAX Request āĻĒāĻžāĻ āĻžāύ⧋:

Traditional JavaScript āĻ:

// GET request āĻāϰ āϜāĻ¨ā§āϝ
fetch('/api/data')
  .then(response => {
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    return response.text();
  })
  .then(data => {
    document.getElementById('result').innerHTML = data;
  })
  .catch(error => {
    console.error('Error:', error);
    document.getElementById('result').innerHTML = 'Error loading data';
  });
HTMX āĻ:

<button hx-get="/api/data" hx-target="#result">
  Load Data
</button>

🔹 Form Submission:

Traditional JavaScript āĻ:

document.getElementById('myForm').addEventListener('submit', function(e) {
  e.preventDefault();

  const formData = new FormData(this);

  fetch('/submit', {
    method: 'POST',
    body: formData
  })
  .then(response => response.text())
  .then(data => {
    document.getElementById('response').innerHTML = data;
  })
  .catch(error => {
    console.error('Error:', error);
  });
});
HTMX āĻ:

<form hx-post="/submit" hx-target="#response">
  <input type="text" name="username" placeholder="Username">
  <button type="submit">Submit</button>
</form>

🔹 Event Handling:

Traditional JavaScript āĻ:

document.getElementById('searchInput').addEventListener('keyup', function() {
  const query = this.value;

  if (query.length > 2) {
    fetch('/search?q=' + encodeURIComponent(query))
      .then(response => response.text())
      .then(data => {
        document.getElementById('searchResults').innerHTML = data;
      });
  }
});
HTMX āĻ:

<input type="text" 
       hx-get="/search" 
       hx-target="#searchResults"
       hx-trigger="keyup changed delay:300ms"
       name="q"
       placeholder="Search...">

📈 āϏ⧁āĻŦāĻŋāϧāĻž āϤ⧁āϞāύāĻž:

āĻŦāĻŋāώāϝāĻŧTraditional JavaScriptHTMX
āϕ⧋āĻĄā§‡āϰ āĻĒāϰāĻŋāĻŽāĻžāĻŖāĻ…āύ⧇āĻ• āĻŦ⧇āĻļāĻŋ (ā§§ā§Ļā§Ļ+ lines)āĻ…āύ⧇āĻ• āĻ•āĻŽ (ā§Ģ-ā§§ā§Ļ lines)
āĻļ⧇āĻ–āĻžāϰ āϏāĻŽāϝāĻŧāĻ•āϝāĻŧ⧇āĻ• āĻŽāĻžāϏāĻ•āϝāĻŧ⧇āĻ• āĻĻāĻŋāύ
Error HandlingManual implementationBuilt-in support
MaintenanceāĻ•āĻ āĻŋāύāϏāĻšāϜ
PerformanceFramework dependentLightweight (10KB)

🔧 HTMX CDN āĻĻāĻŋāϝāĻŧ⧇ āϏ⧇āϟāφāĻĒ āĻ•āϰāĻžāϰ āĻĒāĻĻā§āϧāϤāĻŋ

āϧāĻžāĻĒ ā§§: Basic HTML āĻĢāĻžāχāϞ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ

āĻĒā§āϰāĻĨāĻŽā§‡ āĻāĻ•āϟāĻŋ āϏāĻžāϧāĻžāϰāĻŖ HTML āĻĢāĻžāχāϞ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ:


<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>āφāĻŽāĻžāϰ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒ</title>
</head>
<body>
    <h1>HTMX āĻŸā§‡āĻ¸ā§āϟ āĻĒ⧇āϜ</h1>
    <p>āĻāϟāĻŋ āφāĻŽāĻžāϰ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒā§āϞāĻŋāϕ⧇āĻļāύ</p>
</body>
</html>

āϧāĻžāĻĒ ā§¨: HTMX CDN āϝ⧋āĻ— āĻ•āϰ⧁āύ

<head> section āĻ HTMX CDN link āϝ⧋āĻ— āĻ•āϰ⧁āύ:

🔹 Stable Version (Recommended):


<script src="https://unpkg.com/htmx.org@1.9.10"></script>

🔹 Latest Version:


<script src="https://unpkg.com/htmx.org@latest"></script>

🔹 Specific Version:


<script src="https://unpkg.com/htmx.org@1.9.10/dist/htmx.min.js"></script>

💡 āϟāĻŋāĻĒ: Production āĻ āϏāĻŦāϏāĻŽāϝāĻŧ specific version āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧁āύāĨ¤

āϧāĻžāĻĒ ā§Š: āϏāĻŽā§āĻĒā§‚āĻ°ā§āĻŖ HTML Structure

HTMX āϝ⧋āĻ— āĻ•āϰāĻžāϰ āĻĒāϰ āϏāĻŽā§āĻĒā§‚āĻ°ā§āĻŖ HTML āĻĢāĻžāχāϞ:


<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>āφāĻŽāĻžāϰ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒ</title>

    <!-- HTMX CDN āϝ⧋āĻ— āĻ•āϰāĻž āĻšāϞ -->
    <script src="https://unpkg.com/htmx.org@1.9.10"></script>

    <!-- Basic CSS Styling -->
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>āφāĻŽāĻžāϰ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒ</h1>
        <p>HTMX āϏāĻĢāϞāĻ­āĻžāĻŦ⧇ load āĻšāϝāĻŧ⧇āϛ⧇!</p>
    </div>
</body>
</html>

đŸ–Ĩī¸ Live Server āĻāϰ āϗ⧁āϰ⧁āĻ¤ā§āĻŦ āĻāĻŦāĻ‚ āϏ⧇āϟāφāĻĒ

🚨 āϕ⧇āύ Live Server āĻĒā§āϰāϝāĻŧā§‹āϜāύ?

1ī¸âƒŖ CORS Policy:

Browser security āĻāϰ āĻ•āĻžāϰāϪ⧇ local files āĻĨ⧇āϕ⧇ AJAX requests block āĻ•āϰ⧇ āĻĻ⧇āϝāĻŧāĨ¤

2ī¸âƒŖ File Protocol Limitation:

file:// protocol āĻ HTTP requests āĻĒāĻžāĻ āĻžāύ⧋ āϝāĻžāϝāĻŧ āύāĻžāĨ¤

3ī¸âƒŖ Same-Origin Policy:

HTMX āĻāϰ āϜāĻ¨ā§āϝ proper HTTP server āĻĒā§āϰāϝāĻŧā§‹āϜāύāĨ¤

4ī¸âƒŖ Real-world Environment:

Production environment āĻāϰ āĻŽāϤ⧋ testing āĻ•āϰāĻžāϰ āϜāĻ¨ā§āϝāĨ¤

đŸ› ī¸ Live Server āϏ⧇āϟāφāĻĒ āĻ•āϰāĻžāϰ āĻŦāĻŋāĻ­āĻŋāĻ¨ā§āύ āωāĻĒāĻžāϝāĻŧ:

1ī¸âƒŖ VS Code Live Server Extension (āϏāĻŦāĻšā§‡āϝāĻŧ⧇ āϏāĻšāϜ):

  1. VS Code āϖ⧁āϞ⧁āύ
  2. Extensions tab āĻ āϝāĻžāύ (Ctrl+Shift+X)
  3. “Live Server” search āĻ•āϰ⧁āύ
  4. Ritwick Dey āĻāϰ Live Server install āĻ•āϰ⧁āύ
  5. HTML āĻĢāĻžāχāϞ⧇ right-click āĻ•āϰ⧇ “Open with Live Server” select āĻ•āϰ⧁āύ

2ī¸âƒŖ Python āĻĻāĻŋāϝāĻŧ⧇ (Python installed āĻĨāĻžāĻ•āϞ⧇):


# Python 3.x āĻāϰ āϜāĻ¨ā§āϝ
python -m http.server 8000

# Python 2.x āĻāϰ āϜāĻ¨ā§āϝ  
python -m SimpleHTTPServer 8000

āϤāĻžāϰāĻĒāϰ browser āĻ http://localhost:8000 āĻ āϝāĻžāύāĨ¤

3ī¸âƒŖ Node.js āĻĻāĻŋāϝāĻŧ⧇:


# http-server install āĻ•āϰ⧁āύ
npm install -g http-server

# Server āϚāĻžāϞ⧁ āĻ•āϰ⧁āύ
http-server

# āĻ…āĻĨāĻŦāĻž npx āĻĻāĻŋāϝāĻŧ⧇
npx http-server

4ī¸âƒŖ PHP āĻĻāĻŋāϝāĻŧ⧇ (PHP installed āĻĨāĻžāĻ•āϞ⧇):


php -S localhost:8000

🎉 āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒā§āϞāĻŋāϕ⧇āĻļāύ āϤ⧈āϰāĻŋ

āϧāĻžāĻĒ ā§§: Main HTML āĻĢāĻžāχāϞ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ

index.html āύāĻžāĻŽā§‡ āĻāĻ•āϟāĻŋ āĻĢāĻžāχāϞ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ:


<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>āφāĻŽāĻžāϰ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒ</title>
    <script src="https://unpkg.com/htmx.org@1.9.10"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .demo-button {
            background: #007bff;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            margin: 10px 5px;
        }
        .demo-button:hover {
            background: #0056b3;
        }
        .result-area {
            background: #f8f9fa;
            border: 2px dashed #dee2e6;
            padding: 20px;
            margin-top: 20px;
            border-radius: 5px;
            min-height: 50px;
        }
        .loading {
            color: #007bff;
            font-weight: bold;
            display: none;
            text-align: center;
            margin: 10px 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🚀 āφāĻŽāĻžāϰ āĻĒā§āϰāĻĨāĻŽ HTMX āĻ…ā§āϝāĻžāĻĒā§āϞāĻŋāϕ⧇āĻļāύ</h1>
        <p>āύāĻŋāĻšā§‡āϰ āĻŦāĻžāϟāύāϗ⧁āϞ⧋āϤ⧇ āĻ•ā§āϞāĻŋāĻ• āĻ•āϰ⧇ HTMX āĻāϰ āĻ•āĻžāϜ āĻĻ⧇āϖ⧁āύ:</p>

        <!-- HTMX Demo Buttons -->
        <button class="demo-button" 
                hx-get="content1.html" 
                hx-target="#demo-result"
                hx-indicator="#loading">
            đŸ“Ĩ āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ ā§§ āϞ⧋āĻĄ āĻ•āϰ⧁āύ
        </button>

        <button class="demo-button" 
                hx-get="content2.html" 
                hx-target="#demo-result"
                hx-indicator="#loading">
            📄 āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ ⧍ āϞ⧋āĻĄ āĻ•āϰ⧁āύ
        </button>

        <button class="demo-button" 
                hx-get="content3.html" 
                hx-target="#demo-result"
                hx-indicator="#loading">
            đŸŽ¯ āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ ā§Š āϞ⧋āĻĄ āĻ•āϰ⧁āύ
        </button>

        <!-- Loading Indicator -->
        <div id="loading" class="loading">
            🔄 āϞ⧋āĻĄ āĻšāĻšā§āϛ⧇...
        </div>

        <!-- Result Area -->
        <div id="demo-result" class="result-area">
            āĻāĻ–āĻžāύ⧇ HTMX response āĻĻ⧇āĻ–āĻžāĻŦ⧇...
        </div>
    </div>
</body>
</html>

āϧāĻžāĻĒ ā§¨: Content āĻĢāĻžāχāϞāϏāĻŽā§‚āĻš āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ

📄 content1.html:


<div style="background: #d4edda; padding: 20px; border-radius: 8px; border-left: 4px solid #28a745;">
    <h3>🎉 āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ ā§§ āϏāĻĢāϞāĻ­āĻžāĻŦ⧇ āϞ⧋āĻĄ āĻšāϝāĻŧ⧇āϛ⧇!</h3>
    <p><strong>āϝāĻž āϘāĻŸā§‡āϛ⧇:</strong></p>
    <ul>
        <li>✅ āφāĻĒāύāĻŋ āĻŦāĻžāϟāύ⧇ āĻ•ā§āϞāĻŋāĻ• āĻ•āϰ⧇āϛ⧇āύ</li>
        <li>✅ HTMX āĻāĻ•āϟāĻŋ GET request āĻĒāĻžāĻ āĻŋāϝāĻŧ⧇āϛ⧇</li>
        <li>✅ Server āĻĨ⧇āϕ⧇ āĻāχ HTML content āĻāϏ⧇āϛ⧇</li>
        <li>✅ Page refresh āĻ›āĻžāĻĄāĻŧāĻžāχ content update āĻšāϝāĻŧ⧇āϛ⧇</li>
    </ul>
    <p><strong>āϏāĻŽāϝāĻŧ:</strong> <span id="time1"></span></p>
    <script>
        document.getElementById('time1').textContent = new Date().toLocaleString('bn-BD');
    </script>
</div>

📄 content2.html:


<div style="background: #cce5ff; padding: 20px; border-radius: 8px; border-left: 4px solid #007bff;">
    <h3>đŸŽ¯ āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ ⧍ - Target Demo āϏāĻĢāϞ!</h3>
    <p>āĻāχ content āϟāĻŋ <code>hx-target="#demo-result"</code> āĻĻāĻŋāϝāĻŧ⧇ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ element āĻ load āĻšāϝāĻŧ⧇āϛ⧇āĨ¤</p>
    <p><strong>Target āĻāϰ āϏ⧁āĻŦāĻŋāϧāĻž:</strong></p>
    <ul>
        <li>✅ āϝ⧇āϕ⧋āύ⧋ element āĻ content load āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ</li>
        <li>✅ Multiple targets āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ</li>
        <li>✅ CSS selector āĻĻāĻŋāϝāĻŧ⧇ target āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ</li>
    </ul>
</div>

📄 content3.html:


<div style="background: #fff3cd; padding: 20px; border-radius: 8px; border-left: 4px solid #ffc107;">
    <h3>⚡ āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ ā§Š - Interactive Demo!</h3>
    <p>āĻāϟāĻŋ āĻāĻ•āϟāĻŋ interactive content exampleāĨ¤</p>

    <!-- Nested HTMX Example -->
    <button style="background: #28a745; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;"
            hx-get="nested-content.html" 
            hx-target="#nested-result">
        🔄 āφāϰāĻ“ āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ āϞ⧋āĻĄ āĻ•āϰ⧁āύ
    </button>

    <div id="nested-result" style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px;">
        āĻāĻ–āĻžāύ⧇ nested content āĻĻ⧇āĻ–āĻžāĻŦ⧇...
    </div>
</div>

📄 nested-content.html:


<div style="background: #e8d5ff; padding: 15px; border-radius: 6px; border-left: 3px solid #9b59b6;">
    <h4>🎊 Nested Content āϏāĻĢāϞ!</h4>
    <p>āĻāϟāĻŋ āĻĒā§āϰāĻŽāĻžāĻŖ āĻ•āϰ⧇ āϝ⧇ HTMX response āĻāϰ āĻ­āĻŋāϤāϰ⧇āĻ“ HTMX attributes āĻ•āĻžāϜ āĻ•āϰ⧇āĨ¤</p>
    <p><strong>Loaded at:</strong> <span id="nested-time"></span></p>
    <script>
        document.getElementById('nested-time').textContent = new Date().toLocaleString('bn-BD');
    </script>
</div>

🔍 āϕ⧋āĻĄ āĻŦā§āϝāĻžāĻ–ā§āϝāĻž:

📖 HTMX Attributes āĻāϰ āĻŦāĻŋāĻ¸ā§āϤāĻžāϰāĻŋāϤ:

1ī¸âƒŖ hx-get="content1.html":
  • āĻ•āĻžāϜ: content1.html āĻĢāĻžāχāϞ⧇ GET request āĻĒāĻžāĻ āĻžāϝāĻŧ
  • āĻ•āĻ–āύ: Button āĻ click āĻ•āϰāϞ⧇ (default trigger)
  • Response: HTML content return āĻ•āϰ⧇
2ī¸âƒŖ hx-target="#demo-result":
  • āĻ•āĻžāϜ: Response āϟāĻŋ #demo-result element āĻ āĻĻ⧇āĻ–āĻžāϝāĻŧ
  • Method: innerHTML āĻĻāĻŋāϝāĻŧ⧇ content replace āĻ•āϰ⧇
  • Selector: CSS selector āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇
3ī¸âƒŖ hx-indicator="#loading":
  • āĻ•āĻžāϜ: Request āϚāϞāĻžāĻ•āĻžāϞ⧀āύ #loading element āĻĻ⧇āĻ–āĻžāϝāĻŧ
  • Auto Hide: Response āφāϏāϞ⧇ automatically hide āĻšāϝāĻŧ
  • CSS: display: none/block toggle āĻ•āϰ⧇

🔍 Browser Developer Tools āĻĻāĻŋāϝāĻŧ⧇ HTMX āĻĄāĻŋāĻŦāĻžāĻ—āĻŋāĻ‚

đŸ› ī¸ DevTools āĻ–ā§‹āϞāĻžāϰ āωāĻĒāĻžāϝāĻŧ:

  • Windows/Linux: F12 āĻŦāĻž Ctrl+Shift+I
  • Mac: Cmd+Option+I
  • Right-click: “Inspect Element” āĻŦāĻž “āĻĒāϰ⧀āĻ•ā§āώāĻž āĻ•āϰ⧁āύ”
  • Menu: Browser menu → More Tools → Developer Tools

📊 HTMX Debugging āĻāϰ āϜāĻ¨ā§āϝ āϗ⧁āϰ⧁āĻ¤ā§āĻŦāĻĒā§‚āĻ°ā§āĻŖ Tabs:

1ī¸âƒŖ Network Tab:

  • HTMX Requests āĻĻ⧇āĻ–āĻž: āϏāĻŦ AJAX requests track āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • Request Headers: āĻ•āĻŋ data āĻĒāĻžāĻ āĻžāύ⧋ āĻšāĻšā§āϛ⧇ āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • Response Headers: Server āĻĨ⧇āϕ⧇ āĻ•āĻŋ āφāϏāϛ⧇ āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • Response Time: Performance measure āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • Status Codes: Success/Error status āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ

2ī¸âƒŖ Console Tab:

  • HTMX Errors: āϏāĻŦ error messages āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāĻŦ⧇āύ
  • JavaScript Logs: console.log() messages
  • HTMX Events: Event monitoring āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • Manual Commands: HTMX API functions test āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ

3ī¸âƒŖ Elements Tab:

  • DOM Changes: Real-time āĻ DOM updates āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāĻŦ⧇āύ
  • HTMX Attributes: āϏāĻŦ attributes inspect āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • CSS Classes: Dynamic class changes track āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ
  • Event Listeners: Attached events āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ

🔧 HTMX Specific Debugging Techniques:

1ī¸âƒŖ HTMX Logging Enable āĻ•āϰāĻž:


// Console āĻ āĻāχ command āϚāĻžāϞāĻžāύ
htmx.logAll();

// āĻ…āĻĨāĻŦāĻž HTML āĻ āϝ⧋āĻ— āĻ•āϰ⧁āύ
<script>
    htmx.logAll();
</script>

2ī¸âƒŖ Specific Events Listen āĻ•āϰāĻž:


// Request āĻļ⧁āϰ⧁ āĻšāĻ“āϝāĻŧāĻžāϰ āφāϗ⧇
document.body.addEventListener('htmx:beforeRequest', function(evt) {
    console.log('Request āĻĒāĻžāĻ āĻžāύ⧋ āĻšāĻšā§āϛ⧇:', evt.detail);
});

// Request āĻļ⧇āώ āĻšāĻ“āϝāĻŧāĻžāϰ āĻĒāϰ⧇
document.body.addEventListener('htmx:afterRequest', function(evt) {
    console.log('Response āĻĒ⧇āϝāĻŧ⧇āĻ›āĻŋ:', evt.detail);
});

// Content swap āĻšāĻ“āϝāĻŧāĻžāϰ āφāϗ⧇
document.body.addEventListener('htmx:beforeSwap', function(evt) {
    console.log('Content swap āĻšāĻšā§āϛ⧇:', evt.detail);
});

// Error handling
document.body.addEventListener('htmx:responseError', function(evt) {
    console.error('HTMX Error:', evt.detail);
});

3ī¸âƒŖ Manual HTMX Commands:


// Manual AJAX request
htmx.ajax('GET', '/api/data', '#target');

// Element āĻ trigger āĻ•āϰāĻž
htmx.trigger('#myButton', 'click');

// HTMX attributes add āĻ•āϰāĻž
htmx.process(document.getElementById('myElement'));

🐛 Common Debugging Scenarios:

1ī¸âƒŖ Request āĻĒāĻžāĻ āĻžāύ⧋ āĻšāĻšā§āϛ⧇ āύāĻž:

  • ✅ Live Server āϚāĻžāϞ⧁ āφāϛ⧇ āĻ•āĻŋāύāĻž check āĻ•āϰ⧁āύ
  • ✅ HTMX CDN properly load āĻšāϝāĻŧ⧇āϛ⧇ āĻ•āĻŋāύāĻž āĻĻ⧇āϖ⧁āύ
  • ✅ HTML syntax āĻ āĻŋāĻ• āφāϛ⧇ āĻ•āĻŋāύāĻž verify āĻ•āϰ⧁āύ

2ī¸âƒŖ Response āφāϏāϛ⧇ āĻ•āĻŋāĻ¨ā§āϤ⧁ āĻĻ⧇āĻ–āĻžāĻšā§āϛ⧇ āύāĻž:

  • ✅ hx-target selector āϏāĻ āĻŋāĻ• āφāϛ⧇ āĻ•āĻŋāύāĻž check āĻ•āϰ⧁āύ
  • ✅ Target element DOM āĻ āφāϛ⧇ āĻ•āĻŋāύāĻž verify āĻ•āϰ⧁āύ
  • ✅ Response āĻ valid HTML āφāϛ⧇ āĻ•āĻŋāύāĻž āĻĻ⧇āϖ⧁āύ

3ī¸âƒŖ Loading indicator āĻ•āĻžāϜ āĻ•āϰāϛ⧇ āύāĻž:

  • ✅ hx-indicator selector āĻ āĻŋāĻ• āφāϛ⧇ āĻ•āĻŋāύāĻž check āĻ•āϰ⧁āύ
  • ✅ Indicator element āĻāϰ CSS display property āĻĻ⧇āϖ⧁āύ
  • ✅ Request duration āϝāĻĨ⧇āĻˇā§āϟ āĻ•āĻŋāύāĻž test āĻ•āϰ⧁āύ

✅ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ ā§§ āϏāĻžāϰāϏāĻ‚āĻ•ā§āώ⧇āĻĒ

đŸŽ¯ āφāϜ āϝāĻž āĻļāĻŋāĻ–āϞ⧇āύ:

  • ✓ HTMX āĻĒāϰāĻŋāϚāϝāĻŧ: āĻ•āĻŋ, āϕ⧇āύ āĻāĻŦāĻ‚ āĻ•āĻŋāĻ­āĻžāĻŦ⧇ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻŦ⧇āύ
  • ✓ JavaScript āϤ⧁āϞāύāĻž: Traditional JavaScript vs HTMX āĻāϰ āĻĒāĻžāĻ°ā§āĻĨāĻ•ā§āϝ
  • ✓ Setup Process: CDN āĻĻāĻŋāϝāĻŧ⧇ HTMX āϏ⧇āϟāφāĻĒ āĻ•āϰāĻžāϰ āĻĒāĻĻā§āϧāϤāĻŋ
  • ✓ Live Server: āϕ⧇āύ āĻĒā§āϰāϝāĻŧā§‹āϜāύ āĻāĻŦāĻ‚ āĻ•āĻŋāĻ­āĻžāĻŦ⧇ āϏ⧇āϟāφāĻĒ āĻ•āϰāĻŦ⧇āύ
  • ✓ First App: āĻĒā§āϰāĻĨāĻŽ working HTMX application āϤ⧈āϰāĻŋ
  • ✓ Debugging: Browser DevTools āĻĻāĻŋāϝāĻŧ⧇ HTMX debug āĻ•āϰāĻžāϰ āωāĻĒāĻžāϝāĻŧ

🔧 āĻŽā§‚āϞ HTMX Attributes āϝāĻž āĻļāĻŋāϖ⧇āϛ⧇āύ:

  • hx-get: GET request āĻĒāĻžāĻ āĻžāύ⧋āϰ āϜāĻ¨ā§āϝ
  • hx-target: Response āϕ⧋āĻĨāĻžāϝāĻŧ āĻĻ⧇āĻ–āĻžāĻŦ⧇ āϤāĻž āύāĻŋāĻ°ā§āϧāĻžāϰāĻŖ
  • hx-indicator: Loading state āĻĻ⧇āĻ–āĻžāύ⧋āϰ āϜāĻ¨ā§āϝ

đŸŽ¯ āĻĒāϰāĻŦāĻ°ā§āϤ⧀ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ⧇ āϝāĻž āĻļāĻŋāĻ–āĻŦ⧇āύ:

āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ ⧍: HTTP Methods āĻŦāĻŋāĻ¸ā§āϤāĻžāϰāĻŋāϤ

  • hx-get, hx-post, hx-put, hx-delete, hx-patch
  • āϕ⧋āύ Method āĻ•āĻ–āύ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻŦ⧇āύ
  • RESTful API concepts
  • Form handling āĻāĻŦāĻ‚ data submission

🏠 Practice āĻ•āϰāĻžāϰ āϜāĻ¨ā§āϝ:

  1. āĻāĻ•āϟāĻŋ āύāϤ⧁āύ HTML āĻĒ⧇āϜ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ
  2. HTMX CDN āϝ⧋āĻ— āĻ•āϰ⧁āύ āĻāĻŦāĻ‚ Live Server āϚāĻžāϞ⧁ āĻ•āϰ⧁āύ
  3. ā§ŠāϟāĻŋ āφāϞāĻžāĻĻāĻž content āĻĢāĻžāχāϞ āϤ⧈āϰāĻŋ āĻ•āϰ⧁āύ
  4. āĻŦāĻŋāĻ­āĻŋāĻ¨ā§āύ āĻŦāĻžāϟāύ āĻĻāĻŋāϝāĻŧ⧇ āϏ⧇āϗ⧁āϞ⧋ load āĻ•āϰāĻžāϰ āĻšā§‡āĻˇā§āϟāĻž āĻ•āϰ⧁āύ
  5. DevTools āĻĻāĻŋāϝāĻŧ⧇ Network tab āĻāĻŦāĻ‚ Console monitor āĻ•āϰ⧁āύ

🚀 āĻĒāϰāĻŦāĻ°ā§āϤ⧀ āϧāĻžāĻĒ

āĻāχ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ āϏāĻŽā§āĻĒā§‚āĻ°ā§āĻŖ āĻ•āϰāĻžāϰ āĻĒāϰ āφāĻĒāύāĻŋ āϟāĻŋāωāĻŸā§‹āϰāĻŋāϝāĻŧāĻžāϞ ⧍: HTTP Methods āĻ āϝ⧇āϤ⧇ āĻĒāĻžāϰ⧇āύ āϝ⧇āĻ–āĻžāύ⧇ GET, POST, PUT, DELETE āĻāĻŦāĻ‚ PATCH āĻāϰ āĻŦāĻŋāĻ¸ā§āϤāĻžāϰāĻŋāϤ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻļāĻŋāĻ–āĻŦ⧇āύāĨ¤

Happy Coding! 🎉

How can we help?