← All examples

Morph vs innerHTML

Both panels re-fetch the same fragment every four seconds. Type into either field and watch what survives the swap. The left uses the default innerHTML swap; the right uses the morph plugin.

Normal swap minu-swap="innerHTML"

The target’s children are replaced. Input state dies with them.

Loading…

Morph plugin minu-swap="morph"

Matching nodes are reused. Typed text, focus, and selection stay.

Loading…

The server keeps changing the field’s value attribute. On the right, the input node is reused, so the browser keeps what you typed. On the left, the input is thrown away and rebuilt from the response.

How it works

  1. Both targets call the same endpoint, /demo/morph.
  2. The left target uses the default swap: replace children with fresh HTML.
  3. The right target uses minu-swap="morph".
  4. The morph plugin matches elements by id, position, and tag, then updates attributes and text in place.
  5. Register the plugin before minu.init() so the first load already uses morph.
<div minu-get="/demo/morph"
     minu-trigger="every 4s"
     minu-swap="morph"></div>

<script src="../../dist/minu.min.js"></script>
<script src="../../dist/minu.morph.min.js"></script>
<script>
    minu.registerSwap('morph', minuMorph);
    minu.init();
</script>

The plugin is separate from the core build. See the migration guide and the other swap modes.