According to a survey by Unbounce, 82% of consumers said that slow page speeds impacted their purchasing decisions. If you own a small business or ecommerce website, your page loading speeds could – quite literally – make or break your growth goals.
To keep people on your website and encourage them to make a purchase, you need to optimise your page speed as much as possible. Caching is vital for improving page loading speeds, but what exactly is caching, and how can you use it on your VPS (virtual private server)?
What is caching?
Caching is a temporary storage location for copies of data, such as files, scripts, code and images. During the caching process, copies of frequently accessed data are stored in a computer’s memory so that they can be quickly retrieved in the future. The data will be easier to access because it won’t have to be requested and downloaded again from the primary database (e.g. the server).
In practice, this means that data is automatically stored on your computer the first time you visit a website or use an app. When you visit this website or app again, the data can be easily retrieved from the cache so that the page can load much more quickly.
So, what happens when data is stored in the cache but the website updates before you visit it again?
To deal with this issue, caches have an expiry period. After this period, the caching system checks with the host server to see if there have been any changes to the site. If there have been changes, the cache will automatically update so that users can see the latest version of the website.
What are the benefits of VPS caching?
The primary benefit of VPS caching is that it improves the page loading speed of your website. Nowadays, consumers won’t wait more than a couple of seconds for a page to load, so if you want to reduce your bounce rate and keep people coming back to your site, you need to optimise your page speeds.
Another benefit of caching is that it reduces the load on your server. Since there won’t be as many requests to your VPS for data, this will protect the server and minimise the risk of poor performance or crashes.
Why should I use VPS caching?
Caching is essential if you want to speed up your website, reduce strain on your VPS and attract more online customers.
To get started with VPS caching, you need to know how to install your own caching software and plugins. For a step-by-step guide on choosing your VPS, connecting to it and managing software, read our article on how to set up a VPS. Once you’ve set up your VPS, use one of the VPS caching methods below.
Best VPS caching methods
Now that we’ve established the importance of caching, it’s time to figure out how you can create caches to boost the speed and performance of your VPS. Luckily, there are various VPS caching methods available, so let’s look at the top three.
1. Server-side caching
One of the most effective methods is server-side caching. With this method, you’ll need to install caching software to allow your server to store data in a cache and load your website more efficiently. Luckily, with a VPS, you’ll have full root access to customise your server and install your own software.
Server-side caching is generally recommended for static sites that don’t update their content too often. This is because commonly accessed web pages will be copied to a cache within the server, ready to be used as soon as a user clicks on the page. This will prevent the server from having to recreate and send the same page over and over again.
Some of the most popular caching software options include:
- Varnish: This is an HTTP accelerator that stores all of the HTML/CSS codes for your web pages. Whenever a new request is made, Varnish saves this request and the content that’s been asked for. When this request is made again, the data will come straight from the Varnish cache within your VPS so that the server doesn’t have to process the request again.
- Memcached/Memcached with PHP: This is a memory-caching system that speeds up sites that use databases.
- Squid: This is a caching and forwarding HTTP web proxy. It can cache repeated requests and frequently used web pages.
To learn more about installing caching software on your VPS, read our helpful guide on installing software on dedicated and virtual servers.
2. Browser caching
The opposite of server-side caching is browser caching, also known as client-side caching. With browser caching, copies of web pages are temporarily stored in the browser memory rather than the cache in the server. Images, HTML pages, CSS files and other types of multimedia files can all be cached in the web browser.
To ensure that certain files on your web pages are cached in the web browser, you need to set file headers that instruct the browser to cache them. Cache-control HTTP headers are used to define browser caching policies, which can include how and where a resource is cached and its maximum age before expiring.
The cache-control header is broken up into directives – here are the most common ones:
- Cache-control: max-age. This sets the amount of time before a cached copy expires.
- Cache-control: no-cache. This means a browser can cache a response but must first send a validation request to an origin server.
- Cache-control: no-store. This means a browser isn’t allowed to cache a response – this directive is commonly used for sensitive data such as banking details.
- Cache-control: public. This allows a resource to be cached by any cache.
- Cache-control: private. This indicates that a resource is user-specific and can only be cached on a client device.
3. WordPress caching: Third-party caching plugins
If you’re hosting a WordPress website on your VPS, you can take advantage of plugins that aid your caching and page speeds. Popular WordPress caching plugins include WP Super Cache, Cache Enabler, and W3 Total Cache.
The best plugins will automatically cache pages as static files and also turn on recommended caching settings, such as cache pre-loading, page cache and gzip compression. Features such as gzip compression are used to compress files to allow for faster network transfers, speeding up your WordPress site.