specify cache validation error

How to fix Specify a Cache Validator Warning

If you’ve ever run a webpage speed test using tools like GTmetrix, Google’s PageSpeed Insights, or Pingdom, you may have come across a warning like “Specify a cache validator”.

specify a cache validator warning

GTmetrix.com “Specify a cache validator” warning

 

But what does this mean and how do you fix it?

 

The “Specify a cache validator” warning will appear in your speed test results when there’s no caching solution present on your website or one of its resources. But before we dive deeper into this, let’s first understand what web caching is and why you should care.

What is Web Caching?

 

Web caching is the process of storing a copy of your site’s data that is frequently accessed by a site visitor so that the next time that site visitor lands on your website, the data can be presented to the user without re-executing the scripts or asking your server to deliver the content.

 In other words, it gives your server and the resources you have available a break from having to work so hard when your website experiences repeat visitors.

There are two types of cache: software or hardware based. 

Software Cache

Software cache involves a caching software that’s installed on the same server your website is installed. These include caching solutions like Varnish, Redis, or Memcached and are often provided to you as part of you web hosting plan.

Hardware Cache

Server-based caches, also called “caching proxies” or hardware cache, are usually servers that sit between your website’s server and your site visitors. They also cache your website content so it can be delivered faster to repeat visitors.

 

Content Delivery Networks (CDNs) fall into this category. Popular examples of CDNs include Cloudflare, StackPath, Fastly, and KeyCDN. When a user requests a webpage, CDNs store that page and its resources depending on its configuration.

 

Once a visitor requests that page again, instead of going to the origin web server (where the website is hosted), the CDN automatically returns the requested content – instantly.

 

This process is very powerful. For example, if a shared web server has a limit of 10,000 visitors per month, you’ll run out of available resources pretty quickly if your site is growing.

 

 However, if your webpages are returned by a CDN or caching server, the request does not hit your web server and is not counted towards the monthly visitor quota.

 

 In addition, CDNs have servers spanning the globe. When a site visitor lands on your site, the CDN that’s geographically closest to that user will deliver your site’s cached content. This significantly reduces latency and increases your site’s speed and performance

CDN server locations

(Source)

 

And to think, popular CDNs such as Cloudflare have servers in based in 90 countries and 194 cities!

What Is the “Specify a Cache Validator” Warning? 

 

Now that you have a basic understanding of web caching, let’s take a look at what the “Specify a cache validator” warning is and how to fix it.

Browser caching is an important part of your site’s overall speed and performance.

Every web browser has a cache built into it that saves copies of resources such as images, CSS, and JavaScript files for repeat visitors. When a user reloads a webpage they’ve already been to, the browser will deliver the files saved in its cache. But this only works if you have a proper caching solution set up.

 When you don’t have a caching solution on your website or server, the user’s web browser can’t decide whether the file should be cached or not. So, it always opts not to cache the data.

 This means that every time the same site visitor lands on your website and wants to view a webpage, your site and server have to reload all the resources to deliver the content. This equates to slower load times and a poor user experience.

 It also means you’ll end up with a “Specify cache a validator” warning when you run speed tests.

 It’s important to mention here that a single resource is often used on multiple webpages or sometimes across your entire website. So, if it’s already cached in a web browser, the browser doesn’t need to download it again, no matter where the site visitor is on your website. 

This is normally performed using “Cache-Control” or “Last-Modified” headers, which tell browsers when this resource or file was last modified on the server and how long it should be saved in its cache.

Chrome Developer Tools

                                                    Cache-Control and Last-Modified headers in Chrome Developer Tools

Third-Party Resources

 

Keep in mind, this warning will also show when you’re using third-party scripts like Facebook Pixel or Google Analytics.

gtmetrix third party resource error

 

Third-party resources showing “Specify a Cache Validator” warning

 Since these resources are hosted on their own servers, you have no control over them. So, you can safely ignore these warnings.

How to Fix “Specify a Cache Validator” Warning

There are a few methods for fixing the “Specify a cache validator” warning:

  1. Using a caching plugin (free or premium options available)
  2. With an FTP client such as Filezilla
  3. In your hosting account’s cPanel

1. Using a Caching Plugin

With WordPress, fixing the “Specify a cache validator” warning using a caching plugin is easy. In fact, if you’re using a caching plugin like WP-Rocket , W3 Total Cache or WP Super Cache, this fix is done automatically for you you’ve installed and activated the plugin on your site and have configured its settings.

 

Keep in mind that WP-Rocket is a premium caching solution, W3 Total Cache has both free and paid versions, and WP Super Cache is a free plugin. So, take a look at what each plugin offers

and choose the one that best meets your needs.

 

Note: you should never use multiple caching plugins on your WordPress website as this will likely cause conflicts and is overkill. If you’re an advanced user or web developer who understands this and must use multiple plugins, make sure you don’t enable the same feature in two plugins at the same time.

2. Using an FTP Client Such as Filezilla

If for some reason you don’t want to use a caching plugin on your website, you can fix the “Specify a cache validator” warning manually using an FTP client such as Filezilla or WinSCP. For this example, we’ll use Filezilla. 

First, create a backup your entire WordPress website, database and all, just in case something goes wrong while you’re editing the code.

 Next, log into your FTP client using the following details from your web hosting account:

 

  • Host
  • Username
  • Password

filezilla login screenshot

 

Sometimes, you web host will also designate a specific port number you can enter while logging into your FTP client.

Once you’ve logged into an FTP client using your hosting credentials, your site’s server will connect to your local computer so you can easily make changes.

backend of hosting file manager

When you’re in the FTP client, right-click on the file called labeled .htaccess and click Edit. This should open the file in your default text editor.

where to edit cache settings

 

Add the following code to the text editor:

 

### ADDING EXPIRE HEADERS

<IfModule mod_expires.c>

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 text/css “access 1 month”

ExpiresByType application/pdf “access 1 month”

ExpiresByType application/javascript “access 1 month”

ExpiresByType application/x-javascript “access 1 month”

ExpiresByType application/x-shockwave-flash “access 1 month”

ExpiresByType image/x-icon “access 1 year”

ExpiresDefault “access 7 days”

</IfModule>

### end of ADDING EXPIRE HEADERS

It will look like this in the text editor:

adding expired headers to .htccess

 

When you close the text editor, make sure to save your changes.

The code you added to the htaccess file tells the web browser to cache the following:

 

  • Images for 1 year
  • PDF, JS, and other files for 1 month (since they likely change more often and the cache needs to be updated)
  • Other files for 7 days

3. Using a Web Host cPanel

 

Another easy way to fix the “Specify a cache validator warning” without using a WordPress plugin is to access your htaccess file through your host’s cPanel (or similar control panel).

To access the cPanel, log into your hosting account, click on the My Accounts tab, and click the red Go to cPanel button.

siteground cpanel login

 

Scroll down to the section labeled Files and click on the File Manager icon.

 

file manager in cpannel

 

When the modal window pops up, click Web Root (public_html/www) and then Go. Make sure the checkbox Show Hidden Files (dotfiles) is clicked so you can see the htaccess file.

 

web root show hidden files

 

From the files list inside, right-click .htaccess and then click Edit.

 

edit .htaccess in cpannel

 

This should open a text-editor where you can edit the htacess file. Add the following code to this file at the bottom:

 

### ADDING EXPIRE HEADERS

 <IfModule mod_expires.c>

 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 text/css “access 1 month”

 ExpiresByType application/pdf “access 1 month”

 ExpiresByType application/javascript “access 1 month”

 ExpiresByType application/x-javascript “access 1 month”

 ExpiresByType application/x-shockwave-flash “access 1 month”

 ExpiresByType image/x-icon “access 1 year”

 ExpiresDefault “access 7 days”

 </IfModule>

### end of ADDING EXPIRE HEADERS

This is what it will look like in the text editor:

expires code for image, javascript, etc

Click Save to save your edits.

The code you added to the htaccess file tells the web browser to cache the following:

 

  • Images for 1 year
  • PDF, JS, and other files for 1 month (since they likely change more often and the cache needs to be updated)
  • Other files for 7 days

Verify You’ve Fixed the Warning

 

The last thing you’ll need to do is verify that you’ve fixed the “Specify a cache validator” warning.

To do this, use Developer Tools in any browser (usually toggled by pressing F12).

verify fixed specified cache warning 

Cache-control header showing 1 year (31536000 seconds) after enabling caching via .htaccess

 

The cache-control header for this GIF file now shows 31,536,000 seconds, which is one year, as specified in the .htaccess file.

In the Case of a NGINX-Based Web Server

In case you’re using an NGINX-based web server instead of Apache, you can add the following code to your configuration file:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {

    expires 7d;

This code can be added to the main configuration file /etc/nginx/nginx.conf

 

The best approach, however, is to add this code to the default configuration file /etc/nginx/sites-available/default or the site-specific file located in the folder /etc/nginx/sites-available, such as /etc/nginx/sites-available/example.com.conf.

 

Note: example.com is the placeholder we used to show you the process. You’ll need to replace ‘example.com’ with you own domain name. 

Final Thoughts

In the end, running routine speed tests of your WordPress website is the best way to ensure your site loads blazing fast, performs the way it should, and delivers an exceptional user experience to all site visitors.

But more than that, you should focus on the suggestions given when your site fails to perform at its best. Not many people know about the “Specify a cache validator” warning, let alone know how to fix it. But it’s an easy thing to fix, no matter the method you use, and there’s really no excuse for not doing do.

That said, if you find yourself having trouble fixing the “Specify a cache validator” warning, or need help with other speed optimization on your WordPress website, get in touch with Revealize today. We offer specialized WordPress speed optimization services that are designed to improve loading times, the user experience, and your success as a growing website. In fact, we even have hosting and CDN options available so you don’t have to worry about any speed test result warnings ever again.

Leave a Comment

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

Scroll to Top