PHPackages                             spatie/laravel-server-side-rendering - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/laravel-server-side-rendering

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/laravel-server-side-rendering
====================================

Server side rendering JavaScript in your Laravel application

1.6.0(4mo ago)675525.6k↓37.9%623MITPHPPHP ^7.3|^8.0CI passing

Since Jan 18Pushed 1mo ago17 watchersCompare

[ Source](https://github.com/spatie/laravel-server-side-rendering)[ Packagist](https://packagist.org/packages/spatie/laravel-server-side-rendering)[ Docs](https://github.com/spatie/laravel-server-side-rendering)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-server-side-rendering/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (24)Used By (3)

Server side rendering JavaScript in your Laravel application
============================================================

[](#server-side-rendering-javascript-in-your-laravel-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/88cdcac96782e45ed38d5bba26841f3886a5dd70ca4379725236e164b53a27dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d7365727665722d736964652d72656e646572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-server-side-rendering)[![GitHub Workflow Status](https://github.com/spatie/laravel-server-side-rendering/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-server-side-rendering/actions/workflows/run-tests.yml/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/113551f2c4f347f53bf7d5f671a58a43fe4de91928caa75048a8068eb28e5081/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d7365727665722d736964652d72656e646572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-server-side-rendering)

Making server side rendering a bit less hard in Laravel.

```

        My server side rendered app

        {!! ssr('js/app-server.js') !!}

```

This package is a Laravel bridge for the [spatie/server-side-rendering](https://github.com/spatie/server-side-rendering) library. Before getting started, dig through the readme to learn about the underlying concepts and caveats. This readme also assumes you already have some know-how about building server rendered JavaScript apps.

Vue and React example apps are available at [spatie/laravel-server-side-rendering-examples](https://github.com/spatie/laravel-server-side-rendering-examples) if you want to see it in action.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/c5e3db27fb94d16f3f7dafd076a64a97253bc163dfbb48f07d5d087ffc994fbf/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7365727665722d736964652d72656e646572696e672e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-server-side-rendering)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-server-side-rendering
```

The service provider and `Ssr` alias will be automatically registered.

You can optionally publish the config file if you want to tweak things.

```
php artisan vendor:publish --provider="Spatie\Ssr\SsrServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

### Prerequisites

[](#prerequisites)

First you'll need to pick an engine to execute your scripts. The server-side-rendering library ships with V8 and Node engines. By default, the package is configured to use node, since you probably already have that installed on your system.

Set up the `NODE_PATH` environment variable in your .env file to get started:

```
NODE_PATH=/path/to/my/node

```

You'll also need to ensure that a `storage/app/ssr` folder exists, or change the `ssr.node.temp_path` config value to something else.

If you'd rather use the V8 engine, you can skip the previous two steps. You'll need to have the [v8js extension](https://github.com/phpv8/v8js) installed though.

### Configuration

[](#configuration)

Besides the above, no configuration's required. If you need to tweak things anyway, the [config file](https://github.com/spatie/laravel-server-side-rendering/blob/master/config/ssr.php) is well documented.

### Setting up your scripts

[](#setting-up-your-scripts)

You'll need to build two scripts: a server script and a client script. Refer to your frontend-framework-of-choice's documentation on how to build those.

```
mix.js('resources/js/app-client.js', 'public/js')
   .js('resources/js/app-server.js', 'public/js');
```

The server script should be passed to the `ssr` function, the client script should be loaded manually. The package assumes you're using Laravel Mix, and will resolve the path for you. You can opt out of this behaviour by setting `mix` to `false` in the config file.

```
{!! ssr('js/app-server.js') !!}

```

Your server script should call a `dispatch` function to send the rendered html back to the view. Here's a quick example of a set of Vue scripts for a server-rendered app. Read the [spatie/server-side-rendering](https://github.com/spatie/server-side-rendering#core-concepts) readme for a full explanation of how everything's tied together.

```
// resources/js/app.js

import Vue from 'vue';
import App from './components/App';

export default new Vue({
    render: h => h(App),
});
```

```
// resources/js/app-client.js

import app from './app';

app.$mount('#app');
```

```
// resources/js/app-server.js

import app from './app';
import renderVueComponentToString from 'vue-server-renderer/basic';

renderVueComponentToString(app, (err, html) => {
    if (err) {
        throw new Error(err);
    }

    dispatch(html);
});
```

### Rendering an app in your view

[](#rendering-an-app-in-your-view)

The package exposes an `ssr` helper to render your app.

```

        My server side rendered app

        {!! ssr('js/app-server.js')->render() !!}

```

A facade is available too.

```

        My server side rendered app

        {!! Ssr::entry('js/app-server.js')->render() !!}

```

Rendering options can be chained after the function or facade call.

```

        My server side rendered app

        {!! ssr('js/app-server.js')->context('user', $user)->render() !!}

```

Available options are documented at [spatie/server-side-rendering](https://github.com/spatie/server-side-rendering#rendering-options).

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

### Security

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

67

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity58

Moderate usage in the ecosystem

Community33

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~140 days

Recently: every ~279 days

Total

22

Last Release

131d ago

Major Versions

0.2.5 → 1.0.12018-09-04

PHP version history (5 changes)0.1.0PHP ^7.0

1.1.0PHP ^7.1

1.4.0PHP ^7.2

1.4.2PHP ^7.3

1.4.3PHP ^7.3|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (40 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (33 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (7 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (4 commits)")[![tutNichts](https://avatars.githubusercontent.com/u/2473492?v=4)](https://github.com/tutNichts "tutNichts (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![CWDN](https://avatars.githubusercontent.com/u/1649191?v=4)](https://github.com/CWDN "CWDN (2 commits)")[![Magiczne](https://avatars.githubusercontent.com/u/8850255?v=4)](https://github.com/Magiczne "Magiczne (2 commits)")[![MammutAlex](https://avatars.githubusercontent.com/u/10599196?v=4)](https://github.com/MammutAlex "MammutAlex (2 commits)")[![andredewaard](https://avatars.githubusercontent.com/u/7560637?v=4)](https://github.com/andredewaard "andredewaard (1 commits)")[![erikn69](https://avatars.githubusercontent.com/u/4933954?v=4)](https://github.com/erikn69 "erikn69 (1 commits)")[![reed-jones](https://avatars.githubusercontent.com/u/11511864?v=4)](https://github.com/reed-jones "reed-jones (1 commits)")[![richardkeep](https://avatars.githubusercontent.com/u/3874381?v=4)](https://github.com/richardkeep "richardkeep (1 commits)")[![cbl](https://avatars.githubusercontent.com/u/29352871?v=4)](https://github.com/cbl "cbl (1 commits)")[![serdud](https://avatars.githubusercontent.com/u/17123820?v=4)](https://github.com/serdud "serdud (1 commits)")[![timrspratt](https://avatars.githubusercontent.com/u/20431294?v=4)](https://github.com/timrspratt "timrspratt (1 commits)")[![gbrabyn](https://avatars.githubusercontent.com/u/62121142?v=4)](https://github.com/gbrabyn "gbrabyn (1 commits)")[![traubisoda](https://avatars.githubusercontent.com/u/1913152?v=4)](https://github.com/traubisoda "traubisoda (1 commits)")

---

Tags

javascriptphpserver-side-renderingssrspatieSSRlaravel-server-side-rendering

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-server-side-rendering/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-server-side-rendering/health.svg)](https://phpackages.com/packages/spatie-laravel-server-side-rendering)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-multitenancy

Make your Laravel app usable by multiple tenants

1.4k3.4M20](/packages/spatie-laravel-multitenancy)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
