# Using W3 Total Cache and GTmetrix to optimise WordPress

> Speed up your WordPress site by setting up caching with W3 Total Cache and measuring the results with GTmetrix.

Source: https://helpcenter.ruachost.com/wordpress/guides/using-w3-total-cache-and-gtmetrix-to-optimize-wordpress/

As your WordPress site grows in traffic and content, performance can slow down because WordPress must recompile pages for every visitor. By combining **W3 Total Cache** (for caching) with **GTmetrix** (for performance testing), you can significantly improve speed and efficiency on **ruachost.com** hosting.

## Why Use These Tools?

- **W3 Total Cache** → Adds caching functionality to WordPress, reducing server workload.
- **GTmetrix** → Measures site performance and provides actionable recommendations.
- Together, they help ensure faster page loads, better SEO, and improved user experience.

## Step‑by‑Step Guide

### 1. Install GTmetrix Plugin

1. Log in to WordPress as an administrator.
2. Go to **Plugins → Add New**.
3. Search for **GTmetrix**.
4. Click **Install Now**, then **Activate**.
5. In the sidebar, click **GTmetrix**.
6. Obtain a free **GTmetrix API Key** at gtmetrix.com/api.
7. Enter your account email and API key in the plugin settings.
8. Save changes.

✅ You can now run performance tests directly from your WordPress dashboard.

### 2. Run a Performance Test

1. In WordPress, go to **GTmetrix → Tests**.
2. Click **Test your Front Page Now**.
3. Review the graded score and click **Detailed Report** for insights.
4. Use the waterfall chart to identify slow resources.

### 3. Install W3 Total Cache Plugin

1. In WordPress, go to **Plugins → Add New**.
2. Search for **W3 Total Cache**.
3. Click **Install Now**, then **Activate**.
4. Go to **Performance → General Settings**.
5. Enable the following:

   - ### Page Cache
   - ### Minify
   - ### Database Cache
   - ### Object Cache
   - ### Browser Cache
6. Save all settings.

⚠️ If you see the error *“The required directives for fancy permalinks could not be detected”*, go to **Settings → Permalinks**, choose a non‑default option, and save changes.

### 4. Verify and Re‑Test

1. Clear the cache: **Performance → Empty All Caches**.
2. Refresh your homepage a few times to generate initial cache.
3. Run another GTmetrix test to confirm improved performance.

### 5. Advanced Options

- **Memcached or Redis** → If supported by your hosting plan, configure W3 Total Cache to use these for faster caching.
- **Expires Headers** → Add directives in `.htaccess` to enable browser caching:

  ```
  ## EXPIRES CACHING ##
  ExpiresActive On
  ExpiresByType image/jpg "access 1 year"
  ExpiresByType image/jpeg "access 1 year"
  ExpiresByType image/gif "access 1 year"
  ExpiresByType image/png "access 1 year"
  ExpiresByType application/pdf "access 1 month"
  ExpiresByType application/x-shockwave-flash "access 1 month"
  ExpiresByType image/x-icon "access 1 year"
  ExpiresDefault "access 2 days"
  ## EXPIRES CACHING ##
  ```

> **Note:**
- GTmetrix provides **PageSpeed** and **YSlow** scores with detailed recommendations.
- W3 Total Cache is compatible with all **ruachost.com** accounts.
- Always back up your site before enabling advanced caching options.

##
