Skip to main content
All CollectionsCookbook
Caching with Blitz
Caching with Blitz
Matt Gray avatar
Written by Matt Gray
Updated over 9 months ago

Blitz is a powerful Craft CMS plugin that uses caching to improve page load times. It's used widely on Servd, and easy to setup.

  1. Using the Craft Control Panel's Plugin Store, or composer on the command line, install the Blitz plugin.

  2. Navigate to the Blitz plugin settings in your Craft Control Panel.

  3. Under the Cache Storage tab, set the storage type to "Yii Cache Storage".

  4. Create a new bundle and deploy your changes.

Integrating Blitz With Servd's Static Cache

Because Servd has the ability to run your Craft project in a load balanced configuration, it isn't directly compatible with Blitz's suggested 'server rewrites' setup. However, we can integrate Blitz with the Servd Static Cache as a 'reverse proxy cache'.

This allows all of the site's cache settings to be defined within the Blitz plugin, whilst also leveraging the speed and throughput made available by the static caching layer.

To get set up with this configuration:

  1. Install both the Blitz and Servd plugins in your Craft project

  2. In the Servd Plugin Settings, set:

    • Cache Clear Trigger: Never

    • Cache Clear Strategy: Full Purge

  3. In the Blitz plugin settings, set:

    • Caching Enabled: On

    • Cache Storage: Yii Cache Storage

    • Cache Generator: HTTP Generator

    • Reverse Proxy Purging: Servd Static Cache Purger
      โ€‹

  4. In the Servd dashboard, on the [Environment] > Settings page, set:

    • Static Caching: Enabled

    • Default Cache TTL: Use Origin Headers

    • Include query params in cache keys: On, with Include all query params selected.

  5. With all of these settings saved, Servd's Static Cache will begin caching your content as per the caching rules defined within the Blitz plugin's settings. Blitz will also be able to purge URLs within the static cache as required.

Craft Commands

Blitz provides loads of useful Craft commands for manipulating the data currently cached by your project.

To avoid serving stale data, it's often a good idea to refresh the cache whenever you deploy changes to your project. You can do this by adding Blitz's `blitz/cache/refresh` command as a Post Deploy Task in the "Build & Deploy" Project Settings page.

If you'd like to manually run a Blitz command, navigate to your project, then to the environment you'd like to run it in (e.g. Production or Staging), then to the "Commands" page. From there, scroll to "Run a Craft CLI Command" and execute the command.

Did this answer your question?