Skip to content

Commit 2280d97

Browse files
committed
Add documentation for deferred loading of components
1 parent ab74929 commit 2280d97

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,32 @@ To validate only on "change", use the ``on(change)`` modifier:
21752175
class="{{ _errors.has('post.content') ? 'is-invalid' : '' }}"
21762176
>
21772177

2178+
Deferring the Loading
2179+
---------------------
2180+
2181+
Certain components might be heavy to load. You can defer the loading of these components
2182+
until after the rest of the page has loaded. To do this, use the ``defer`` attribute:
2183+
2184+
.. code-block:: twig
2185+
2186+
{{ component('SomeHeavyComponent', { defer: true }) }}
2187+
2188+
Doing so will render an empty "placeholder" tag with the live attributes. Once the ``live:connect`` event is triggered,
2189+
the component will be rendered asynchronously.
2190+
2191+
By default the rendered tag is a ``div``. You can change this by specifying the ``loading-tag`` attribute:
2192+
2193+
.. code-block:: twig
2194+
2195+
{{ component('SomeHeavyComponent', { defer: true, loading-tag: 'span' }) }}
2196+
2197+
If you need to signify that the component is loading, use the ``loading-template`` attribute.
2198+
This lets you provide a Twig template that will render inside the "placeholder" tag:
2199+
2200+
.. code-block:: twig
2201+
2202+
{{ component('SomeHeavyComponent', { defer: true, loading-template: 'spinning-wheel.html.twig' }) }}
2203+
21782204
Polling
21792205
-------
21802206

0 commit comments

Comments
 (0)