PHP code example of buzzingpixel / craft-static

1. Go to this page and download the library: Download buzzingpixel/craft-static 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/ */

    

buzzingpixel / craft-static example snippets


\buzzingpixel\craftstatic\Craftstatic::$plugin->getStaticHandler()->handleContent();



namespace some\module\namespace;

use yii\web\Response;
use craft\web\Controller;
use buzzingpixel\craftstatic\Craftstatic;

class MyController extends Controller
{
    protected $allowAnonymous = true;
    
    public function actionSomeAction(): Response
    {
        // ... do stuff

        $response = $this->renderTemplate($template, $vars);
        
        // Potentially check an environment variable so you don't cache
        // in dev environment
        if (getenv('STATIC_CACHE_ENABLED') === 'true') {
            Craftstatic::$plugin->getStaticHandler()->handleContent(
                $response->data
            );
        }

        return $response;
    }
}


return [
    'cachePath' => realpath(dirname(__DIR__)) . '/web/cache',
];
bash
* * * * * /user/bin/php /path/to/projet/craft craft-static/cache/check-tracking >> /dev/null 2>&1