PHP code example of bnomei / kirby3-staticache

1. Go to this page and download the library: Download bnomei/kirby3-staticache 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/ */

    

bnomei / kirby3-staticache example snippets


return [
  'cache' => [
    'pages' => [
      'active' => true,
      'type' => 'static'
    ]
  ],
  // other options
];

return [
  'cache' => [
    'pages' => [
      'active' => true,
      'type' => 'static',
      'ignore' => function ($page) {
        return $page->template()->name() === 'blog';
      }
    ]
  ],
  // other options
];

    
    he(__DIR__ . '/static');
    
    echo (new Kirby)->render();


    // static cache file
    $staticache = __DIR__ . '/static/' . (
        !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] . '/' : ''
    ) . 'index.html';
    // load static cache headers
    if (file_exists($staticache) && file_exists($staticache . '.json')) {
        foreach (json_decode(file_get_contents($staticache . '.json'), true) as $header) {
            header($header);
        }
    }
    // load static cache html
    if (file_exists($staticache)) {
        die(file_get_contents($staticache));
    }

    

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }