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/ */
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;
}
}