Server Side Rendering with Laravel + Phantomjs
, (*1)
Did someone say Server Side Rendering with Laravel?, (*2)
This package adds a middleware on your Laravel websites that capture GET requests with _escaped_fragment_.
The url will be rendering with Phantomjs and will be cached with Laravel Cache Drive, (*3)
To make the magic, just add <meta name="fragment" content="!"> to the <head> of all pages that you want to be indexed. (maybe master.blade.php), (*4)
More info about escaped_fragment, (*5)
Dependencies
Installation
You can install this package via composer, (*6)
composer require mixdinternet/laravel-ssr
In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:, (*7)
'providers' => [
...
Mixdinternet\SSR\Providers\SSRServiceProvider::class,
];
You can publish the config file with:, (*8)
php artisan vendor:publish --provider="Mixdinternet\SSR\Providers\SSRServiceProvider" --tag="config"
Phantomjs Instalation
Get your copy of Phantomjs here, (*9)
Extract the file and put the content of bin folder in storage/app, (*10)
It will looks like something like this storage/app/phantonjs, (*11)
Don't worry, you can change this in config/ssr.php =), (*12)