PHPackages                             buzzingpixel/craft-static - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. buzzingpixel/craft-static

AbandonedArchivedCraft-plugin[Caching](/categories/caching)

buzzingpixel/craft-static
=========================

Static file caching for Craft 3

2.0.1(6y ago)143.3k2[3 issues](https://github.com/buzzingpixel/craft-static/issues)[1 PRs](https://github.com/buzzingpixel/craft-static/pulls)Apache-2.0PHPPHP &gt;=7.2

Since Oct 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/buzzingpixel/craft-static)[ Packagist](https://packagist.org/packages/buzzingpixel/craft-static)[ RSS](/packages/buzzingpixel-craft-static/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (7)Dependencies (13)Versions (8)Used By (0)

Craft Static
============

[](#craft-static)

Static file caching for Craft 3
-------------------------------

[](#static-file-caching-for-craft-3)

Installing
----------

[](#installing)

(Please see section below for instructions on setting up the cron job to clear cache for future or expiring entries)

### Composer

[](#composer)

From the command line run:

`composer require buzzingpixel/craft-static`

After installing via composer, go to your Craft CP &gt; Settings &gt; Plugins and install Craft Static.

### Craft Plugin Store

[](#craft--plugin-store)

The other way is through the plugin store in the Craft CP.

Configuration
-------------

[](#configuration)

There are two globally configurable options:

- `cachePath` - defaults to `$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'cache'`
- `nixBasedClearCache` - defaults to `true`. Leave set to true on Unix based systems because it clears the cache by executing `rm -rf` which is much faster. Otherwise, PHP has to iterate through each file and directory in the cache path and delete them individually, which can take some time.

Usage
-----

[](#usage)

### Usage in Twig

[](#usage-in-twig)

The entire contents of your HTML output should be wrapped in the `{% static %}` tag so it's best to put this in the outermost layout file. You can also specify whether the tag should actually cache or not so you can disable caching in some scenarios and still wrap your entire contents in the tag.

Example:

```
{% set shouldCache = true %}
{% static cache shouldCache %}
    {% minify %}

            Test title

            Test body

    {% endminify %}
{% endstatic %}
```

### Alternative usage in a controller

[](#alternative-usage-in-a-controller)

If you would like to use a controller to render your output, or otherwise statically cache from PHP, you can use:

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

A full(er) example:

```
