Selecteur de langue

When working with WordPress, it’s common to hear—or say—“Did you remember to clear the cache?” when something isn’t working as expected. It’s like the classic troubleshooting step of unplugging and reconnecting your router when the internet acts up.

And it’s true: in many cases, clearing the cache can resolve issues with your website. In fact, while preparing this article, I noticed that the most common WordPress cache searches were clear WordPress cache and how do I clear WordPress cache? That’s how common—and essential—it is.

So why use WordPress cache plugins if they sometimes cause problems? Can’t we just skip them?

No, of course not. When caching is properly configured, it delivers significant benefits for all site users.

In this post, I’ll detail my method for optimizing your WordPress website without spending days on it. As always, I prefer using lightweight tools that are simple to configure and don’t clutter the WordPress admin interface, so we don’t “enshittify” the experience. Also, since I’m committed to keeping everything local, I avoid CDNs or other online services.

Configuring Page Caching on WordPress

Page caching allows you to serve your site’s visitors a “pre-computed” version of the page they’re viewing. In other words, if the page has already been visited, your WordPress site delivers this saved version directly to the visitor’s browser, rather than “recalculating” the content through multiple requests.

How Does WordPress Display Content?

  1. The visitor clicks a link to your site, sending an HTTP request to your server.
  2. The server receives the request and forwards it to WordPress.
  3. WordPress runs scripts to determine what to display, dynamically generates HTML content based on the request and the data stored in your database, then sends this content back to the server.
  4. The server sends the HTML content to the visitor’s browser, which interprets it along with other resources (CSS, JavaScript, etc.) to display the web page.

Optimization with Cache

To improve site speed and avoid repeating this process for every visit, the dynamically generated HTML content is saved after the first visit. This “pre-calculated” version of the page is then delivered directly to subsequent users, significantly speeding up load times and reducing server load.

Data Compression

In addition to caching, using Gzip or Brotli compression further reduces page load times. These algorithms shrink the size of files transmitted between the server and browser, speeding up data transfer. To implement this caching system on a WordPress site, I use the free Cache Enabler plugin by KeyCDN.

Cache Enabler is a small, lightweight caching plugin that’s easy to configure in just a few clicks. When combined with plugins dedicated to static resource and object caching, it’s an excellent alternative to other caching solutions like WP Rocket or WP Super Cache.

➡️ How to Configure Cache Enabler

Optimize and cache static resources

Static resources are files that don’t change dynamically and are served as-is to visitors when they access a site.

They include:

  • Stylesheets (CSS).
  • JavaScript (JS) files.
  • Images (JPG, PNG, WEBP, etc.).
  • Fonts.

To improve the performance of a WordPress site, I handle it in two steps:

  1. Minify and concatenate CSS and JS.
  2. Implement an effective caching policy for all static resources.

CSS & JS: Minifying and Concatenating

I base my approach on Harry Roberts’ work and his publication The Three Cs: 🤝 Concatenate, 🗜️ Compress, 🗳️ Cache. You’ll find detailed measurements and explanations there.

Each theme and plugin that adds functionality to the user interface (frontend) of a site will include its own CSS and JS files. To minimize page weight, I first ensure these files are only loaded on the pages where they’re needed.

Then, I apply this simple, time-tested method:

  1. Minify CSS and JS.
  2. Concatenate all CSS into a single file (without affecting CSS embedded in the page’s HTML).
  3. Concatenate all JavaScript (JS) into a single file and place it in the footer (likewise, leave JS embedded in the page untouched).

For this step, I use the Autoptimize plugin by Optimizing Matters.

➡️ How to Configure Autoptimize (post forthcoming).

Why Concatenate?

Even though HTTP/2 is widely adopted today—allowing unlimited parallel requests, unlike HTTP/1’s six-request limit—a single large file can still perform better on WordPress due to latency and compression.

Latency

Latency is the time it takes to establish a connection and begin transferring data before the actual download starts. To put it simply: think of latency as the time it takes to open a door before entering a room. Each new network connection requires this “opening time.”

In this context, each static file requires a new connection, which adds to the total latency. The more files you have, the more latency accumulates, increasing the time it takes to download all files. Many WordPress sites are hosted on small, shared servers that may not be very efficient, further increasing server response time. If the server only has one request to process, performance improves.

Compression

Compression works by detecting and eliminating redundancy. The larger a file, the more repetitions it contains, allowing the compression algorithm to optimize it effectively. Conversely, small files offer fewer opportunities for compression. Their limited size means fewer redundancies, so the algorithm has less to work with. The headers and metadata required for compression also take up a larger proportion of the final file, reducing the real benefit of compression. This is why concatenating static resources lets you fully leverage compression, which you can easily enable with Cache Enabler.

Note: Concatenation isn’t suitable for all sites. Every WordPress installation has its own quirks. If in doubt, test your site’s performance with and without concatenation.

An Aggressive Caching Policy with Cache Headers

Simply put, cache headers are instructions sent by the server to the visitor’s browser (or other intermediaries like proxies) about how to handle files.

To reduce server load, we minimize how often static files need to be resent. We do this by adding instructions that tell visitors’ browsers how long they can store a local copy of the site’s static files without requesting them from the server again.

Rules to add to .htaccess

#BEGIN CACHE CONTROL
<FilesMatch "\.(ico|flv|jpg|jpeg|png|gif|webp|css|js|woff|woff2|ttf|eot|svg)$">
    Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access 1 year"
    ExpiresByType application/javascript "access 1 year"
    ExpiresByType application/font-woff "access 1 year"
    ExpiresByType application/font-woff2 "access 1 year"
    ExpiresByType application/x-font-ttf "access 1 year"
    ExpiresByType application/vnd.ms-fontobject "access 1 year"
    ExpiresByType image/svg+xml "access 1 year"
    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 image/webp "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
#END CACHE CONTROLCode language: Apache (apache)

This aggressive caching policy sets the retention time for most static resources (CSS, JS, images, fonts, etc.) to one year. Unspecified elements, such as PDFs, default to a one-month retention period.

These guidelines are general, so feel free to add your own rules based on the types of files your site uses.

The Object Cache

The object cache is a mechanism that stores frequently accessed data in RAM or a fast storage system. Instead of repeatedly querying the database, previously requested data is served directly from this cache. Without it, each page view requires new database calls, which can slow down your site.

Several plugins allow you to configure different types of object caching for WordPress.

SQLite3 & APCU

If you have only one WordPress site on your hosting and are unsure whether Redis or Memcached is supported, I recommend the SQLite Object Cache plugin.

➡️ How to Configure SQLite Object Cache (publication forthcoming).

Redis

If your web host provides a Redis cache server, this may be a good option. Sites using Redis have both an SQL database and a non-SQL storage server: Redis. You can use the Redis Object Cache plugin.

➡️ How to Configure Redis Object Cache (publication forthcoming).

Memcached

If your web host supports Memcached, this may be a good option. While I haven’t personally used this object caching system, the recommended plugin in the WordPress.org documentation is Memcached Object Cache.

A Better User Experience with Lightweight Tools

We’ve explored how to combine small, specialized cache plugins to create the best possible experience for both users and administrators.

This approach may require a bit more effort than configuring all-in-one solutions like WP Rocket, WP Fastest Cache, or W3 Total Cache. But once you understand how these tools work together, the results are well worth it!

I hope this post helps you. If you have any questions, need WordPress support, or want to contribute, don’t hesitate to contact me or leave a comment!

Sources

Author

Quentin Le Duff: Your WordPress partner

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *