spatie/laravel-server-side-rendering
Laravel bridge for spatie/server-side-rendering to render JavaScript apps on the server. Provides an ssr() Blade helper/alias to execute server bundles (e.g., Vue/React) and return HTML for faster first paint and SEO-friendly pages.
Install the package via Composer, publish the optional config file, and ensure your environment supports your chosen engine (Node.js or V8js). Start by rendering a minimal SSR-enabled page: create resources/js/app-server.js that renders your component and calls dispatch(html), then use {!! ssr('js/app-server.js') !!} in your Blade layout. For newcomers, review the official examples repo and check the ssr() helper’s signature—it’s the primary entry point you’ll interact with daily.
Most day-to-day usage revolves around replacing client-side mount points with ssr() calls in Blade templates. Common patterns include:
ssr()->context('key', $value) to pass server-side variables (e.g., auth user, config) into the JS contextmix.js('client.js', 'dist').js('server.js', 'dist')Ssr facade for more complex rendering chains (e.g., conditional rendering with ->renderWhen())@section blocks to maintain layout consistency across SSR and non-SSR pagesIntegrate with Laravel Octane by enabling it—this package auto-detects and uses Swoole/RoadRunner workers for persistent JS runtimes—avoiding cold-start latency on repeated requests.
NODE_PATH config and a writable storage/app/ssr directory. V8js is faster but finicky—ensure phpinfo() shows v8js and verify thread-safety in production.Ssr::tryRender() (if available) or fallback to client-only rendering with Blade conditionals.mix() resolution, always re-run npm run dev or npm run build after changing SSR bundles—stale Mix manifest will silently fail.php artisan config:clear after toggling engine configs—changes to ssr.php aren’t hot-reloaded in development.APP_DEBUG=true environments or using ssr()->disabled() in non-critical pages to preserve server resources.How can I help you explore Laravel packages today?