Documentation

Enable Static Caching

In order to get the very best performance from your project, it's worth considering the use of static caching to dramatically accelerate the speed of most requests.

Static caching captures a snapshot of your project's response HTML and stores it in a cache. The next request for the same URL will return the pre-rendered HTML from the cache rather than forwarding the request to PHP for it to build a whole new response.

This strategy can work very well for websites which serve the same content to all users, but can cause issues for projects which rely on user logins or detection of a users country in order to tailor the content that is displayed. However the benefits are huge so if you're not sure whether it'll work for you, just give it a try in your Servd staging environment and see how it goes!

Enabling static caching on Servd is easy and can be fully configured via the dashboard.

NOTE: Static caching is disabled for all users who are logged into the Craft control panel. This allows admin users to check and debug pages throughout a site without worrying about their content being cached or having to try to avoid being served cached content.

Enabling/Disabling Static Caching

  1. Navigate the the Environment > Settings page for the environment that you'd like to change

  2. Find the Static Caching section on the page

  3. Toggle the master enable/disable switch

  4. Click the 'Sync' button at the top of the page to deploy your change

Add Static Caching Exceptions

Whenever you use static caching it is very important to also define exceptions to the caching mechanism.

At a minimum the Craft control panel should be excluded in its entirety.

Static caching exceptions are based on URL prefixes. Any incoming request which begins with one of these prefixes will entirely bypass Servd's static caching mechanism.

  1. Navigate the the Environment > Settings page for the environment that you'd like to change

  2. Find the Static Caching section on the page

  3. Add, remove or edit any required URL prefixes

  4. Click Save

  5. Click the 'Sync' button at the top of the page to deploy your change

Check Whether a Response Came From the Cache

Once static caching has been enabled Servd will begin adding a response header called X-Servd-Cache to indicate whether or not a specific request has been served from the static cache.

You can check this header using the developer tools in your browser. It will be set to one of the following values:

  • MISS - The request was not served from the cache because no cached copy of the page was available
  • HIT - The request was served from the cache
  • BYPASS - The request was not served from the cache because a rule explicitly forbade it (either a URL prefix was matched or the user is logged into the Craft control panel)