ancient-shoe-86801
09/11/2022, 9:20 PMmysterious-toddler-20573
09/11/2022, 10:42 PMancient-shoe-86801
09/11/2022, 10:56 PMHX-Request
request header.
- Includes the Last-Modified
response header to allow the client to cache the response.
- Processes If-Modified-Since
request headers to return a 304 Not modified
, telling the client to use the cached response.
Then:
- The server response must also include Vary: HX-Request
response header alongside the Last-Modified
header.
This tells the client to cache by URL and HX-Request header value, instead of only by URL.
2) Re Etags.
If you have a route on your server which:
- Returns a different response depending on the HX-Request
request header.
- Includes the Etag
response header to allow the client to cache the response.
- Processes Etag
request headers to return a 304 Not modified
, telling the client to use the cached response.
Then:
- The server must generate a different Etag
value for each response. Ideally, it should be some kind of hash of the response, making it unique.
3) How this affects htmx?
No changes on htmx are needed. Everything is working according to HTTP specs.ancient-shoe-86801
09/11/2022, 10:57 PMmysterious-toddler-20573
09/11/2022, 11:07 PMmysterious-toddler-20573
09/12/2022, 12:23 AMmysterious-toddler-20573
09/12/2022, 12:24 AMmysterious-toddler-20573
09/12/2022, 12:24 AMmysterious-toddler-20573
09/12/2022, 12:25 AMhtml
<body hx-ext="morph">
...
<button hx-get="/whatever" hx-swap="morph">
Morph It
</button>
...
</body>
mysterious-toddler-20573
09/12/2022, 12:26 AMouterHTML
and innerHTML
(open to name suggestions)mysterious-toddler-20573
09/12/2022, 12:26 AMproud-librarian-99598
09/12/2022, 7:20 AMboundless-summer-65618
09/12/2022, 9:13 AM<script>
// Initialize the map instance:
var map = L.map('map');
// Map tiles:
[...]
// Create a markers:
var marker = L.marker([51.5, -0.09]).addTo(map);
</script>
This is the basic Leaflet which gets added to bottom of the HTML. How could we dynamically add markers? My first instinct was to insert a div
and use hx-get
inside the script
tag -- do forgive the HTML/JS newbie!!
What I tried:
<script>
[...]
<div hx-get="{% url 'marker_data' %}" hx-trigger="every 5s">
</div>
</script>
The marker_data.html
(Django)
{% for city in cities_all %}
var marker = L.marker([{{city.latitude}}, {{city.longitude}}]).addTo(map)
{% endfor city in cities_all %}
boundless-summer-65618
09/12/2022, 10:21 AM<div id="markers" hx-get="{% url 'marker_data' %}" hx-trigger="every 10s"> </div>
In the Leaflet script:
document.getElementById('markers');
In `marker_data.html`:
<script>
{% for city in cities_all %}
var marker = L.marker([{{city.latitude}}, {{city.longitude}}]).addTo(map)
{% endfor city in cities_all %}
</script>
Very satisfiying to see these markers appear on the map like this!mysterious-toddler-20573
09/12/2022, 4:39 PMmysterious-toddler-20573
09/12/2022, 4:39 PMmysterious-toddler-20573
09/12/2022, 4:40 PMbitter-monkey-50309
09/12/2022, 9:48 PMgorgeous-airport-54386
09/12/2022, 9:49 PMbitter-monkey-50309
09/12/2022, 9:50 PMbland-coat-6833
09/12/2022, 10:21 PMwonderful-shampoo-13605
09/12/2022, 11:11 PMhx-trigger
?bland-coat-6833
09/13/2022, 6:22 AMbland-coat-6833
09/13/2022, 6:35 AMbland-coat-6833
09/13/2022, 7:11 AMgorgeous-ghost-95789
09/13/2022, 1:10 PMhx-trigger
would need to listen for an event. We’d have to double check to be certain, but I think the extensions just try to reconnect instead of notifying you of a disconnect. It shouldn’t be too hard to add an event into them, though.early-camera-41285
09/13/2022, 6:00 PMhtml
<div class="animation" id="my-div">text content</div>
with
html
<div class="animation" id="my-div">different text content</div>
Should the animation continue smoothly? My use case is updating an animated progress bar--not really critical.hundreds-camera-24900
09/13/2022, 6:04 PM<li hx-swap-oob="beforeend:#messages">{% include "components/toast.html" %}</li>
that gets included w/ a template response, would you expect the resulting dom to include the li or not? Currently it doesn't and just has the inner contentsmysterious-toddler-20573
09/13/2022, 6:24 PMmysterious-toddler-20573
09/13/2022, 6:24 PM