rybakit/twig-deferred-extension
Twig extension that lets you defer rendering of heavy blocks and run them later, improving perceived performance. Works with Twig templates to collect deferred parts and flush them when ready—handy for widgets, fragments, and complex layouts.
rybakit/twig-deferred-extension package enables deferred rendering of Twig blocks, which is particularly valuable in Laravel applications where:
jenssegers/laravel-twig, making this extension a natural fit for projects using Twig for templating. For Blade users, this could complement hybrid approaches (e.g., Twig for complex layouts, Blade for dynamic logic).twig.cache and Laravel’s view.cache settings. Consider partial caching strategies for deferred blocks.twig.cache) to mitigate this?jenssegers/laravel-twig or similar).jenssegers/laravel-twig and configure it alongside Blade (or replace Blade entirely).// config/twig.php
'extensions' => [
Rybakit\Twig\DeferredExtension::class,
],
{# Deferred block (renders asynchronously) #}
{% deferred_block 'analytics' %}
{# Analytics script or widget #}
<script src="/analytics.js" defer></script>
{% enddeferred_block %}
{# Critical block (renders synchronously) #}
{% block content %}{% endblock %}
IntersectionObserver to load content when it enters the viewport).document.querySelectorAll('[data-deferred-block]').forEach(el => {
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
fetchDeferredContent(el.dataset.blockId).then(html => {
el.innerHTML = html;
});
}
});
});
observer.observe(el);
});
IntersectionObserver).rybakit/twig-deferred-extension for updates (though it’s lightweight, MIT-licensed, and actively maintained).How can I help you explore Laravel packages today?