Enable the static cache
This task is for administrators of public sites that must cope with sudden demand (an announcement, an emergency). The static cache stores public pages as plain files that the web server sends without starting Exponential. It is off in a new installation (Operating a site, section 4).
Warning
.htaccess slows down every request. When .htaccess files are enabled (AllowOverride anything but None), let alone
used, Apache looks for them and reads and evaluates them on every request, in every directory of the path, and
page loading times go up drastically (measured). The only real fix is to switch the feature off for
the virtual host: AllowOverride None in the HTTPS virtual host, and the rules in the virtual host's own
configuration as mod_rewrite rules. That is far faster in production speed tests and well worth the time it takes
to optimize a production configuration. Switch over right away: copy the rules of the
example HTTPS virtual host into your virtual host (with the static cache, also
staticcache_offload.conf), set AllowOverride None, run apachectl configtest, reload Apache and
test the site. The same rules for other servers: nginx, LiteSpeed,
Caddy, IIS, Velocity (built in); where virtual host rules go in a control
panel: Plesk, cPanel, DirectAdmin, ISPConfig.
On LiteSpeed or OpenLiteSpeed, the server's own page cache can also answer anonymous visitors and crawlers without PHP: Page caching with LiteSpeed and OpenLiteSpeed.
Contents
Before you start
- Only siteaccesses that need no login are offered, because their pages are the same for everybody.
- The web server rules of your installation that serve the static files are active (Apache with the shipped
.htaccess); under Velocity the response cache is the usual alternative (Velocity response cache and HTTP cache). - A change approved for a settings change.
Steps
See what it would do:
php bin/php/cache.php static status --allow-root-userGenerate pages of one site, limited first so you see it work:
php bin/php/makestaticcache.php --site=site --max-pages=500 --max-depth=6 --allow-root-userOmit
--sitefor every public siteaccess. In the browser: Setup > Cache management, section Static content cache, with a Stop button.Switch it on in
settings/override/site.ini.append.php:[ContentSettings] StaticCache=enabledphp bin/php/ezcache.php --clear-tag=ini --allow-root-user, then reload or deploy.
Check it worked
php bin/php/cache.php static status --allow-root-usercounts the files per site invar/site/static.- Publish a change and check the page updates (publishing clears its static pages).
Pitfalls
- Pages that show something personal (a signed-in user's name, a form with a token) must not be static.
- Remove the files with
php bin/php/cache.php static clear --allow-root-userwhen you switch it off again.
Related pages
- Static cache
- Static cache generator
- Static cache (hosting)
- DDoS and probe floods
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.