PHP code example of tsekka / prerender

1. Go to this page and download the library: Download tsekka/prerender library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tsekka / prerender example snippets


// prerender.php:
'whitelist' => [
    '/frontend/*' // only prerender pages starting with '/frontend/'
],

// config/prerender.php 
'blacklist' => [
    '/api/*' // do not prerender pages starting with '/api/'
    // ...
],

php artisan migrate

php artisan vendor:publish --provider="Tsekka\Prerender\PrerenderServiceProvider" --tag="config"
 php
  // app/Http/Kernel.php
    protected $routeMiddleware = [
      // ...
      'prerender' => 
          \Tsekka\Prerender\Http\Middleware\PrerenderMiddleware::class,
    ];

  // routes/web.php
  Route::get('/{path?}', 'SPAController')->where('path', '.*')
      ->middleware('prerender');
  
 php
    // 1. Set up event-listener
    // 2. Inside your listener:
    public function handle($event)
    {
       return \Artisan::call('prerender:cache', [
                'url' => '/your-model-resource-url',
                '--force' => true,
                '--log' => false,
        ]);
    }
 php
    // app/Console/Kernel.php
    protected function schedule(Schedule $schedule)
    {
        // Daily re-cache all urls that's cache-time-to-live is expired
         $schedule->command('prerender:cache')->dailyAt("02:00");
         
        // Daily re-cache all urls
         $schedule->command('prerender:cache --force')->dailyAt("02:00");
    }
 php
    // app/Console/Kernel.php
    protected function schedule(Schedule $schedule)
    {
        // Daily prune all crawler visit entries older than 1 month
        $schedule->command('prerender:prune "1 month"')->daily();
    }