Surge, page caching for everyone

If you are looking for a plugin to cache pages of your website to speed up its loading, stop searching, I present to you Surge, the simplest and most powerful solution to add page caching to your website.

What is page cache?

Among the many caching strategies that you can apply to your content (static, objects, opcache, memcached, reverse proxy, etc.) we have the page cache, which is the most basic, simple, compatible and easy to apply in any hosting, but that doesn’t mean that it isn’t powerful.

Basically, what page caching does is create HTML copies of your web pages to serve them to the visitor on their second visit. On the first visit to a page of your website, a static HTML copy is created.

This way, when a visitor arrives again WordPress will not have to query the database to display the dynamic contents of that page, showing the HTML copy made.

Page caching creates static copies of the dynamic content of your WordPress website, thus speeding up page load times by eliminating the waiting times resulting from the dynamic queries normally required to display content in WordPress.

Well, is that then what Surge does?

Indeed, the Surge plugin, like many other plugins, creates static HTML versions of your pages to reduce page load times by eliminating the need for WordPress to query the database to display its content, showing static copies of your posts, pages, etc.

I already have a cache plugin, why should I switch to Surge?

Depending on the caching strategies you are using on your website you should switch to using Surge, or add it to your WPO toolbox.

If you are already using an optimizer and caching plugin, which also has page caching, like WP Rocket, SiteGround Optimizer or others, you should first check if in these plugins you can deactivate their own page caching system to activate (test) Surge.

For example, if you use SG Optimizer the page (file) cache is optional, and you can activate it at will, but in no case the fact of activating the page cache, SG Optimizer or Surge, means that you have to do without the other cache systems (dynamic, memcached).

What is usually incompatible is to have two page caching systems active at the same time.

Another situation is if you already have a plugin whose only functionality is page caching, such as WP SuperCache or Cache Enabler. In this case the thing is as simple as deactivating it and activating Surge, checking which plugin works best on your website, and deciding.

Here I take this opportunity to remind, once again, that there is not one best cache plugin or optimizations. You should test on each website what combination of optimizations and caching systems work best for the type of content and objectives of the site.

Is Surge compatible with WP Rocket?

Going into detail, and as many people use WP Rocket, I will tell you that initially they are not compatible, and WP Rocket will warn you that there is a problem.

This is because WP Rocket has its own page caching system, and you should not have more than one active, so the message is correct.

Now, if you want to test which of the two plugins is more effective with page caching you can disable WP Rocket’s page cache with this plugin.

Is Surge compatible with WooCommerce?

We all know the importance of NOT caching the sessions of a WooCommerce online store so that the current user’s data is always displayed, not any saved version, which could display information from another customer, right?

Well, this is something that any caching plugin should respect, and NEVER cache the most sensitive pages of WooCommerce, namely:

  • My Account
  • Cart
  • Checkout

These pages should always be excluded from any caching system, ALWAYS.

And yes, Surge is compatible with WooCommerce, it respects the Cache-Control: no-cache headers of WooCommerce dynamic pages, so it will never cache them.

Is Surge compatible with WordPress? (multisite) WordPress?

Yes, totally, you activate it for the network and that’s it.

Is Surge compatible with Cloudflare?

Yes, it does too. Surge is compatible with most HTML proxies, such as Cloudflare. What’s more, by default – unless you enable its full-page cache – Cloudflare only caches resources, not full pages, and Surge creates full-page caches, they are fully compatible and complementary.

Is it possible to exclude pages from the Surge page cache?

If, in addition to WooCommerce dynamic pages, you want to exclude other pages with is_page so that Surge does not make cached copies of them you can do so with a code like the following:

/* Exclude page from caching */ add_action( 'template_redirect', function() { if ( is_page( array( '123', '124', '125' ) ) ) { header( 'Cache-Control: no-cache' ); } } );
Code language: PHP (php)

This function will add the Cache-Control: no-cache header to the pages you specify in the array line, in the example the pages with IDs 123, 124 and 125 (you can also use the page title or the slug).

Needless to say, this function does not work only with Surge, it will work with any caching plugin because what it does is to add the Cache-Control: no-cache header, which is standard and will respect any caching system.

How do I know if the Surge page cache is working?

If you have already installed and activated the Surge plugin, the next thing is to check that it is working properly, for which I suggest you do the following checks:

  1. Check that in the wp-config.php file there is the line define( 'WP_CACHE', true );(Surge adds it automatically when you activate the plugin and removes it when you deactivate it).
  2. Check that the /wp-content/cache/surge/ folder exists, which is where the static copies of your pages will be stored (Surge creates it automatically when you activate the plugin, but does not delete it, if you stop using it, delete this folder because it will take a lot of space).
  3. Check that the /wp-content/advanced-cache.php file has been created and that it indicates in the header that it is a Surge dropin. It will also appear in your list of dropin plugins.
  4. Go to the WordPress site health tool, which usually warns of cache status and issues.
  5. Visit in incognito mode your pages and check that the x-cache-enabled header is set to True.
  6. Check the loading speed of your pages in a measurement tool such as GTMetrix, compared to previous readings. Surge usually offers load times at least 70 times faster than a non-optimized WordPress.

How often is the Surge cache cleared?

Unless you change its default settings, Surge clears the cache every 10 minutes, and every time you publish or update a page/entry.

How is Surge configured?

This is the best of all because in Surge you don’t have to configure anything, in fact, it doesn’t even have any options or settings page. It works perfectly just by activating it.

Now, in addition to what we have already seen above, you can apply some tweaks to its operation by creating a custom configuration file for Surge.

Here’s how to do it:

  1. Create a new file in the root folder of your WordPress installation and name it, for example, configure-cache.php.
  2. Add the following to the file:
    <?php
    return $config;
  3. Add to the wp-config.php file the following line: define( 'WP_CACHE_CONFIG', DIR . '/configure-cache.php' ); . This way we tell Surge where to find your custom configuration file.

And here’s where the good stuff starts. Now open the configure-cache.php file to edit it, and you can configure the $config array with the values you want to change. The available ones are the following:

Array keyValue
ttlThe number of seconds a page is cached before invalidating it.
ignore_cookiesAn array of cookie names that will not cause a page to be excluded from the cache.
ignore_query_varsAn array of URL parameters that will not cause a page to be excluded from the cache.
variantsAn array of cache invalidation “variants” (here you have several)

Set a longer expiration time

An example of how to use the array values in the configuration file would be to set a cache expiration time longer than the default set by the Surge plugin (600 = 10 minutes). This is called the TTL (Time To Live).

In sites with low traffic it would make sense to change the cache expiration, and not to renew it every so little time, wouldn’t it?

So, we could extend the time to live of the cache to 30 minutes (ttl of 1800), changing the values of the $config, in this way:

<?php $config['ttl'] = 1800; return $config;
Code language: HTML, XML (xml)

And this is only an example, from here on PHP is your friend.

How do I clear the Surge cache?

By default, the Surge cache is emptied when publishing posts and pages, but you can also force the total emptying of the page cache in 2 ways:

  1. Activate and deactivate the plugin. When you deactivate it, it clears the cache.
  2. Delete the /wp-content/cache/surge/ folder.

Well, I don’t think I left anything out. I just encourage you to try Surge. If you don’t have any page caching system in place yet, you’re already late, and if you already have it, it never hurts to try it, maybe you’ll get a pleasant surprise and it works better than the current one.

In case you haven’t guessed it already, Surge is totally free.

How useful was this post?

Click on a smiley to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

Leave a Comment

Your email address will not be published.

Scroll to Top
Skip to content