Speeding up WordPress and WooCommerce websites
"My WordPress website is slow" or "My WooCommerce website can't handle large amounts of traffic" are statements I see often in the various communities I belong to. This is often followed by a question like "how can I speed up my website?" which can be hard to answer because... it depends!
What I'd like to cover today, is the main strategies I would employ for a majority of the WordPress website I run or have run. It's not a one-size-fits-all solution but it should definitely give you a push in the right direction. Disclaimer: sometimes performance issues are caused by problematic themes and plugins which no "trick" will solve.
Page cache
Page caching is by far one of the biggest wins from a performance perspective especially for pages that are mostly static. By static, I'm talking about pages that don't have dynamic content. So pages that would be static are blog posts, pages, etc.
The way page caching works is that it generates a single HTML file of a page that consists of PHP handling the request, fetching the content from the database, processing it, and returning the HTML needed to display the page to the visitor. That HTML is saved and the next visitor will just get shown that pre-generated HTML instead of having to go through all the steps to get it. Less PHP processing required and fewer database queries to run.
Dynamic content is slightly harder to cache purely because of its nature. Product pages with tiered pricing, cart pages, and so on have data that change for every visitor. This is not to say that you can't cache these types of pages, it's just slightly harder.
When it comes to page cache, I always turn to one product and that is WP Rocket. Some of the features of WP Rocket are:
- Page caching
- JS and CSS optimisation
- Lazy-loading of images and iframes
- A CDN for globally distributed content
Object cache
For pages that have dynamic data like WooCommerce product pages with pricing and stock amounts, we want to also cache that data to reduce requests to the database. To do this we can use a method that fetches the data from the database and stores the information in memory which is really quick to access. This is known as object cache which essentially storing a copy of the object in memory.
If you're wondering why we don't just store everything by default in memory it's because memory is volatile and loses its information when it loses power (such as a reboot).
WordPress, fortunately, has already got an object cache API and default data is already stored inside of it. The only thing that needs to be added is an in-memory storage system like Redis or Memcache. There are many hosts that already offer Redis or Memcache which you can then use alongside a plugin like Redis Object Cache which handles everything for you.
Using an object cache can make a huge difference when a database makes many calls to the database to get the same information. An example of this is Paid Membership Pro which needs to check the access levels of every single object displayed on a page (which can add up). Storing that data in memory makes the subsequent looks up fast.
WordPress optimised hosting providers
When you've done the above and still wanting to get more speed out of your website, then it's probably time to move to a hosting provider that is built around WordPress and specifically focuses on speed. These hosting providers are not out there to get as many websites on a server as possible which means you're not competing for those precious resources. It does mean, though, that they're not $5 a month.
These hosts usually have a level of page and object caching built-in. They're built to scale with your website and can grow with you as your website goes from a few hundred to millions of visitors. They also support WooCommerce which is important for conversions as for every second a page loads, a site loses customers. My two recommendations:
WP Engine
WP Engine has been around for years and they have proven their ability to host the biggest websites out there. Their pricing is competitive and they offer all the features you need to make sure your website is fast.
Kinsta
Kinsta is my personal favourite (their local development environment is fantastic). They too offer all the features you need to get your website flying but, besides DevKinsta (their local development environment), their support is amazing and they offer a hack recovery guarantee.
Is speed everything?
No, it isn't. It's important but don't get caught up on getting 100/100 on Google Pagespeed Insights as this will take you away from building your website or product(s). This is especially true before you've launched or in the early days of your website.
When you have thousands of people coming to your website every day and hundreds of sales, then focussing on the small gains can equate to large increases in revenue. Doing these small things should get you to this stage very comfortably.
Comments ()