{"id":16272473,"url":"https://github.com/spatie/laravel-server-side-rendering","last_synced_at":"2025-05-14T03:09:17.198Z","repository":{"id":28280918,"uuid":"117847033","full_name":"spatie/laravel-server-side-rendering","owner":"spatie","description":"Server side rendering JavaScript in your Laravel application","archived":false,"fork":false,"pushed_at":"2025-04-10T12:45:30.000Z","size":87,"stargazers_count":669,"open_issues_count":0,"forks_count":63,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-12T17:45:12.428Z","etag":null,"topics":["javascript","php","server-side-rendering","ssr"],"latest_commit_sha":null,"homepage":"https://sebastiandedeyne.com/posts/2018/server-side-rendering-javascript-from-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie"}},"created_at":"2018-01-17T14:25:33.000Z","updated_at":"2025-04-10T12:45:18.000Z","dependencies_parsed_at":"2025-02-21T15:11:37.976Z","dependency_job_id":"c5554862-8283-4f6c-9eb3-4e094b1e6f1a","html_url":"https://github.com/spatie/laravel-server-side-rendering","commit_stats":{"total_commits":75,"total_committers":18,"mean_commits":4.166666666666667,"dds":0.6799999999999999,"last_synced_commit":"03d6b0791b43cb2aaa364168bfb620d3a177c609"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-server-side-rendering","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-server-side-rendering/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-server-side-rendering/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-server-side-rendering/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-server-side-rendering/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059508,"owners_count":22007768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","php","server-side-rendering","ssr"],"created_at":"2024-10-10T18:17:54.868Z","updated_at":"2025-05-14T03:09:17.168Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"# Server side rendering JavaScript in your Laravel application\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-server-side-rendering.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-server-side-rendering)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-server-side-rendering/run-tests.yml?branch=main\u0026label=Tests\u0026style=flat-square)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-server-side-rendering.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-server-side-rendering)\n\nMaking server side rendering a bit less hard in Laravel.\n\n```blade\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eMy server side rendered app\u003c/title\u003e\n        \u003cscript defer src=\"{{ mix('app-client.js') }}\"\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        {!! ssr('js/app-server.js') !!}\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nThis 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.\n\nVue 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.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-server-side-rendering.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-server-side-rendering)\n\nWe 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).\n\nWe 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).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-server-side-rendering\n```\n\nThe service provider and `Ssr` alias will be automatically registered.\n\nYou can optionally publish the config file if you want to tweak things.\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\Ssr\\SsrServiceProvider\" --tag=\"config\"\n```\n\n## Usage\n\n### Prerequisites\n\nFirst 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.\n\nSet up the `NODE_PATH` environment variable in your .env file to get started:\n\n```\nNODE_PATH=/path/to/my/node\n```\n\nYou'll also need to ensure that a `storage/app/ssr` folder exists, or change the `ssr.node.temp_path` config value to something else.\n\nIf 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.\n\n### Configuration\n\nBesides 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.\n\n### Setting up your scripts\n\nYou'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.\n\n```js\nmix.js('resources/js/app-client.js', 'public/js')\n   .js('resources/js/app-server.js', 'public/js');\n```\n\nThe 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.\n\n```blade\n{!! ssr('js/app-server.js') !!}\n\u003cscript src=\"{{ mix('js/app-client.js') }}\"\u003e\n```\n\nYour 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.\n\n```js\n// resources/js/app.js\n\nimport Vue from 'vue';\nimport App from './components/App';\n\nexport default new Vue({\n    render: h =\u003e h(App),\n});\n```\n\n```js\n// resources/js/app-client.js\n\nimport app from './app';\n\napp.$mount('#app');\n```\n\n```js\n// resources/js/app-server.js\n\nimport app from './app';\nimport renderVueComponentToString from 'vue-server-renderer/basic';\n\nrenderVueComponentToString(app, (err, html) =\u003e {\n    if (err) {\n        throw new Error(err);\n    }\n\n    dispatch(html);\n});\n```\n\n### Rendering an app in your view\n\nThe package exposes an `ssr` helper to render your app.\n\n```blade\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eMy server side rendered app\u003c/title\u003e\n        \u003cscript defer src=\"{{ mix('js/app-client.js') }}\"\u003e\u003c/script\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        {!! ssr('js/app-server.js')-\u003erender() !!}\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nA facade is available too.\n\n```blade\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eMy server side rendered app\u003c/title\u003e\n        \u003cscript defer src=\"{{ mix('js/app-client.js') }}\"\u003e\u003c/script\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        {!! Ssr::entry('js/app-server.js')-\u003erender() !!}\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nRendering options can be chained after the function or facade call.\n\n```blade\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eMy server side rendered app\u003c/title\u003e\n        \u003cscript defer src=\"{{ mix('js/app-client.js') }}\"\u003e\u003c/script\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        {!! ssr('js/app-server.js')-\u003econtext('user', $user)-\u003erender() !!}\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nAvailable options are documented at [spatie/server-side-rendering](https://github.com/spatie/server-side-rendering#rendering-options).\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n### Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Sebastian De Deyne](https://github.com/sebastiandedeyne)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-server-side-rendering","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-server-side-rendering","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-server-side-rendering/lists"}