Connect with us
specify-a-cache-validator specify-a-cache-validator

Caching

Specify a Cache Validator

Published

on

Cache validators are defined inside response headers and HTTP requests and are used to determine if whether or not a request to retrieve files from the browser cache are valid.

These validators are important because they work out whether a request needs to be sent to the server, which uses more resources and takes longer, or if the required files can be got from the local cache, thus increasing loading speed and using less resources.

It is always going to be better to retrieve files from the browser cache because it doesn’t involve the round trips that requests to the server involve. Using a cache validator, like an etag header or Last-Modified, can help to ensure that the browser is using caching as efficiently as possible.

How to Specify a Cache Validator

When you use a we serve, such as Nginx or Apache, the Last-Modified header is included by default. When your page speed tool, like GTMetrix or Google Page Speed, come up with the suggestion that you specify a cache validator, you are required to use either Last-Modified header, Etag and Expires Header or Cache Control Max Age header.

Last Modified and Etag headers are used for assisting the browser to work out if the requested file has been altered in any way since it was requested last. Cache Control and Expires header are used for working out how long a file should be stored in the cache before a new copy is requested from the server.

If you don’t use the Expires or Cache control headers, the browser has no way of knowing how long a local cached copy should be stored before a new one is retrieved. These may already have been defined on the server you use but, if you need to define them manually and you use Nginx or Apache, you can use these code snippets:

Apache

<filesMatch “.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Cache-Control “max-age=84600, public”

Nginx

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 2d;
add_header Cache-Control “public, no-transform”;
}

If you wanted to add the Last Modified header straight into a dynamic file, you would need to use the gmstrftime from the PHP file, as in the next example:

header(‘Last-Modified: ‘ . gmdate(‘D, d M Y H:i:s’) . ‘ GMT’);

On occasion, you may be trying to load resources stored on another domain. In this case, your speed test tools would send you a notice that you are required to specify a cache validator for those resources.

You could ignore this notice in safety – just like assets that are loaded from fonts.googleapis.com, for example, you do not have control over setting any cache validator for the resources and there is always a chance that what was specified has been intentionally removed.

Browser caching is a very important factor in WordPress website speed and making sure that you specify the right cache validator, and that it works as it should do, is critical for ensuring that browser caching is being used efficiently and results in speedier page loading.

Click to comment

Caching

Use W3 Total Cache Plugin to Optimize Your WordPress site

Published

on

W3 Total Cache

WordPress is, by default, a dynamic content management system and this means that it must look for every page a visitor requests in the database just to see if it exists.

In most cases, especially where a website doesn’t get too much traffic, this isn’t a problem but, should there be a surge in traffic, your WordPress site will suddenly start using enormous amounts of CPU resources while trying to deal with duplicated requests, over and over.

Stopping this is quite easy to do by using the right caching plugin.

A caching plugin caches the first request from a visitor for a page on the server, in plain HTML so that when that page is requested again, by another visitor, that cached version is served – so long as the page hasn’t been updated in admin or with a comment in the meantime.

This reduces that amount of CPU usage significantly.

Let’s say that you have 50 separate views of your main page and it hasn’t been cached. That would mean 50 queries on the database, each time it just goes back to the same data.

By using a caching plugin, only the first request would be queried on the database and the next 49 would get the cached version immediately, no having to wait for the query to complete.

This is a win-win – you get a reduction in resources used and your visitors get a quicker loading time.

W3 Total Cache

One of the easiest caching plugins to use in WordPress is W3 Total Cache and I’m going to show you how to use it.

  • In your WordPress dashboard, hover your mouse over Plugins and choose Add New
  • Type W3 Total Cache in the search box
  • Click Search Plugins and then click Install Now under W3 Total Cache
  • A window will pop up, click OK
  • Now click on Activate Plugin and you will see a message telling you the plugin has been activated
  • Go to the menu on the left-hand side and you should see a section called Performance – hover the mouse over it and click General Settings
  • Scroll down the page and make sure that each of the main parts has been enabled.

Those parts are:

  • Page Cache
  • Minify*
  • Database Cache
  • Object Cache
  • Browser cache – click Save All Settings once you enable this one

* If you use Minify, enable the option and save it. Straightaway, go straight to your website and make sure it all looks good.

If there are any formatting issues, a plugin or theme may be incompatible with minification. If this is the case, you will either need to change the theme or plugin or disable minification

Now make sure that the following have been check marked and click Save All Settings:

  • Cache home page
  • Cache 404 pages
  • Cache feeds
  • Cache requests only
  • Don’t cache pages for logged-in users

Lastly, ensure that everything has been correctly set up and then go to your website. Open your site, click on View and then Page Source so that you can see the page source.

Scroll down, right to the bottom and you should see a banner for W3 Total Cache. This will tell you that the plugin has optimized your page

When you have confirmed it all and your website is running perfectly, you are done. W3 Total Cache will ensure that your pages load faster, and fewer server resources are used, resulting in happier visitors and fewer bounces.

Continue Reading

Caching

Why Caching is So Important in WordPress

Published

on

caching wordpress

When you look for ways to speed up your WordPress website, one of the first tips you will see is to optimize caching. It is, in fact, one of the most important things you can do yet few people do it.

Maybe that’s because few people understand why it is so important. We all know that it speeds up WordPress, but does it do anything else? How should we employ it to speed up a website?

What is Caching?

Caching is a process by which static versions of website content are created. When a page is first requested, it is cached so that any subsequent requests for that page are then served by the static version, which is rendered much quicker in a web browser.

The result? Faster page loading, happy visitors.

In WordPress, page rendering requires a good deal of database querying, a lot of toing and froing. We can avoid this. When you create a page of content, it’s not likely that you will be updating it every day.

When that page is cached, provided you don’t update it between then and the next request, it gets served to the next visitor, thus cutting out all those to and from queries. The result? Less loading on the server, faster page loading.

Are you beginning to see the picture?

The Benefits of Caching

Caching offers several benefits:

  • It enhances the performance and the speed of your website because files that are statically cached load faster than dynamic queries to the database.
  • It reduces server loading. It saves I/O operations and server memory, making it one of the most critical features of any WordPress website, especially for those who use a limited hosting plan.
  • A faster loading website also gets a better ranking in the search engines, although the final ranking does depend on other metrics, such as content quality, originality, and other SEO metrics. However, a faster loading website will be ranked better than a slow one.
  • Provides a better user experience. Visitors can browse your site better, they don’t use so much bandwidth to load your website and we all know that happy visitors leads to lower bounce rates and higher conversion rates.

So, how do we go about implementing caching? The easiest way is to use a plugin designed to do it all for you and there are lots to choose from, some free, some premium. Here are six of the most popular:

Popular WordPress Caching Plugins

  • WP Super Cache – a simple and free plugin, WP Super Cache generates a static HTML file for each cached page. It is customizable and synchronizes with your CDN. Great for beginners and is kept updated.
  • W3 Total Cache – used on more than a million WordPress websites, this is one of the more popular plugins. It doesn’t just generate static pages; it will also help with minification and compression of web pages, along with using other tools to improve speed. It is more complicated and better for those with a bit of experience.
  • WP Fastest Cache – this another plugin that generates static HTML, but it also offers several other options for optimization. That includes minifying CSS and HTML and speeding up JS scripts. It also has support for GZip compression. This is free but there is also a premium version that offers extra features, including CDN integration
  • Cache Enabler – this is quite a new plugin offering a simple and intuitive interface. It does what it says n the box – caches and serves static HTML. It’s ideal for those who need a simple solution and does not require much in the way of configuration.
  • Comet Cache – a free plugin that offers static HTML generation, supports GZip compression and other optimization, including support for both server-side and browser caching. There is a premium version that has extra support including CDN integrations, the ability to run customized PHP code, and more. The free version will suit beginners, the premium version, not so much.
  • WP Rocket – a premium plugin, WP Rocket has been shown to produce amazing results. It has an intuitive interface, is easy to configure and offers all the optimization features that all the others do, plus a few more besides.

Like every speed optimization and performance improvement solution in WordPress, caching won’t work on its own.

While it will speed things up for you, it is best used in conjunction with other WordPress speed measures.

That said, it’s always a good place to start because a fast loading website always means satisfied customers.

Continue Reading

Categories

Archives

Digital Marketing Job Board

Trending