{% extends "django_sample_components/pages/master_async.html" %} {% load async_tags sample_tags %} {% block title %}Async Lazy Popup{% endblock %} {% block content %}

Async Lazy Popup with HTMX

Modal that fetches its content from the server only when opened.


Load once (default)

Content is fetched only on the first open. Close and reopen — no new request:

{% async_lazy_popup name_button="Open Popup" title="Lazy Popup — Load Once" %}
Reload on every open

Content is re-fetched every time the modal opens. Notice the timestamp updates:

{% async_lazy_popup name_button="Open Popup" title="Lazy Popup — Reload Always" always_reload_on_open=True %}

Lazy popup — Counter loaded on open

The counter is fetched from the server only when the modal is opened:

{% async_lazy_popup name_button="Open (lazy)" title="Counter — Lazy" content_url=counter_url size="sm" always_reload_on_open=True %}
Regular popup — Counter rendered with the page

The counter is rendered immediately as part of the page, even before the modal opens:

{% simple_popup name_button="Open (regular)" title="Counter — Regular" size="sm" %} {% async_counter initial_value=0 step=1 %} {% endsimple_popup %}

How It Works
  1. Click the button — Bootstrap opens the modal immediately, showing a spinner
  2. Bootstrap fires the show.bs.modal event on the modal element
  3. HTMX listens for that event and sends a GET request to content_url
  4. The server response replaces the spinner with the real content
{% endblock %}