suhype/craft-pagecache

Simple HTML Page Cache Plugin

2.1.1 2025-05-02 20:12 UTC

README

Simple but useful Page Cache Plugin.

With this plugin you can create static HTML files of your entries.

Requirements

This plugin requires Craft CMS 3.x or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:
cd /path/to/project
  1. Then tell Composer to load the plugin:
composer require suhype/craft-pagecache
  1. In the Control Panel, go to SettingsPlugins and click the “Install” button for Page Cache.

Page Cache Overview

Page Cache is a Craft CMS plugin which can create static HTML files of your entries.

Configuring Page Cache

Go to SettingsPage Cache to setup the basic configuration options:

  • Enabled caching: Enable or disable the caching. Note: you need to delete the cache manually.
  • Enable gzip compression: Serve gzip compressed cached files.
  • Enable brotli compression: Serve brotli compressed cached files. Only works if the PHP brotli extension is installed.
  • When globals are saved: Choose what happens when globals got saved. Choose between "Refresh cache" & "Delete cache"
  • Excluded URL's: Define URL's which should never be cached (regex possible).
  • Included URL's: Define URL's which should always be cached (regex possible). This options overwrites the Excluded URL's option.
  • Cache folder path: Define a custom path, where cached files should be stored. Aliases (like @webroot) allowed.

Add rewrite rules rules

To speed up your page even more you can add rewrite rules for .htaccess, nginx and apache. You can use the examples for .htaccess (with and without gzip/brotli compression):

The brotli and gzip compressions can be used together, separately or not at all. Just make sure to add them before the normal rewrite rules

Using Page Cache

  • Go to SettingsPage Cache
  • Enable caching and optionally customize the settings
  • As soon as a user visits a page, it got's cached.
  • Optional: go to Entries, mark all cachable entries (→ entries with URL's), and Choose Refresh cache

Delete Page Caches

  • Go to UtilitiesCaches
  • Select Page Cache
  • Click on Clear caches

Console commands

Clear the whole page cache (this is the same as under Utilities):

php craft clear-caches/pagecache

Refresh cache:

# Run `php craft pagecache/refresh --help` to see the possible arguments

php craft pagecache/refresh

Page Cache Roadmap

Some things to do, and ideas for potential features:

  • Add entry action to exclude entries
  • Add config option to include URL's

Brought to you by Benjamin Ammann