https://github.com/sandulat/laratron
๐ผ Laravel SSR using Rendertron ๐ผ
https://github.com/sandulat/laratron
laravel laravel-rendertron laravel-ssr rendertron ssr
Last synced: 9 months ago
JSON representation
๐ผ Laravel SSR using Rendertron ๐ผ
- Host: GitHub
- URL: https://github.com/sandulat/laratron
- Owner: sandulat
- License: mit
- Created: 2019-07-08T10:51:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-01T19:58:49.000Z (almost 6 years ago)
- Last Synced: 2025-07-26T17:53:46.215Z (11 months ago)
- Topics: laravel, laravel-rendertron, laravel-ssr, rendertron, ssr
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 27
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Laratron
๐ผLaravel SSR using Rendertron ๐ผ
## About
Since we know that not all crawlers can render Javascript, we have to implement SSR (Server-Side Rendering). Implementing SSR in Laravel may be a headache and the easiest solution could be [Rendertron](https://github.com/GoogleChrome/rendertron).
**Laratron** is a tiny middleware for your Laravel app that detects whether the visitor is a crawler and passes the request to Rendertron.
About Rendertron (from official Readme):
> Rendertron is designed to enable your Progressive Web App (PWA) to serve the correct content to any bot that doesn't render or execute JavaScript. Rendertron runs as a standalone HTTP server. Rendertron renders requested pages using Headless Chrome, auto-detecting when your PWA has completed loading and serializes the response back to the original request. To use Rendertron, your application configures middleware to determine whether to proxy a request to Rendertron. Rendertron is compatible with all client side technologies, including web components.
## Installation
First of all we need to install Rendertron. Please consult the [official documentation](https://github.com/GoogleChrome/rendertron) for more info.
To install Laratron run this inside your project:
```bash
composer require sandulat/laratron
```
## Configuration
Laratron exposes only one simple option, the URL of Rendertron, which can be set in your env file:
```bash
RENDERTRON_URL=http://localhost:3000
```
## Usage
After installation you can use the middleware **`laratron`** on any route that you'd like to be server-side rendered.
```php
Route::get('/', function () {
return view('home');
})->middleware('laratron');
```
Or you can apply it on the entire `web` middleware group in `App\Http\Kernel`:
```php
'web' => [
// ...
\Sandulat\Laratron\Http\Middleware\LaratronMiddleware::class,
],
```
## Credits
Created by [Stratulat Alexandru](https://twitter.com/sandulat).