Web hosting optimization: speed and performance
Updated on
Introduction to optimization
A slow website significantly reduces the time visitors spend on it. Optimizing your site’s speed is therefore a major factor that you should by no means neglect.
Contrary to popular belief, a site’s slowness does not necessarily come from the slowness of the server hosting it. Of course, an overloaded or poor-quality server can cause slowness, but LRob does everything to rule out this possibility.
In this context, we find that requests about slow websites are, in the vast majority of cases, due to a lack of optimization of the sites in question, hence the usefulness of this article. (Nevertheless, if you notice unusual slowdowns on your site, do not hesitate to contact your support to request a check.)
Optimization can be split into two main parts:
- The resources loaded by the site’s visitors
- The CPU resources used on the server by PHP and MySQL while the site’s pages load
Server resource optimization
The loading time of a page on your site is directly tied to the computing power required to generate it. It is therefore important to make sure that the PHP code generating the pages is as optimized as possible in order to deliver a decent loading time.
Moreover, a site that is not optimized, or poorly optimized, can in some extreme cases even slow down an entire server. If, for example, each page triggers very long MySQL queries (more than 20 seconds) and the site receives several visits per second, the server’s CPU usage can quickly reach 100% and performance will degrade dramatically, and the server may even stop responding.
In addition, it is important to understand that PHP uses only one processor core per process (and therefore per page loaded). This means that your site’s page load time will not be faster with 8 cores than with 2 cores if there is only one visitor, but on the other hand, you will be able to serve more visitors simultaneously without slowdowns.
The following optimizations are valid for all CMSs (WordPress, Joomla, etc.)
Common mistakes to avoid
To save time, let’s start with the approaches that will only waste your time and should therefore be avoided.
- Piling up plugins: Most plugins load on every page, slowing your site down a little more each time. In addition, some may conflict, and adding many plugins multiplies the risk of running into bugs.
- Using caching plugins (WPSupercache, WPRocket…): Caching systems can cause many problems, and dynamic pages, if they still work, will remain slow. You need to tackle the problem at its source rather than use a stopgap that is generally much less effective than real optimization.
- Keeping an outdated site with an obsolete PHP version: Besides the dramatic security problem this causes, you potentially divide your site’s performance by 1.5 to 3.
Updates
Make sure your CMS is up to date, as well as all its themes, modules, extensions, etc.
PHP version
Make sure you are using the latest supported PHP version (adjustable through your Plesk control panel, each new PHP version since PHP 7.0 improves performance.
Plugins and extensions
- Limit as much as possible the number of plugins/extensions/modules installed; each module is an additional source of slowdown.
- Check that you do not have plugins or modules that are too demanding on performance. Deactivate all modules, check the site’s speed, then reactivate them gradually to find the plugin or plugins slowing the site down. This also applies to themes.
MySQL databases
- Reduce the size of your database.
- The smaller the MySQL database, the better the performance.
- If your database contains connection logs or the like, find a way to clean it periodically (through the back office, a plugin, or phpMyAdmin for example).
- A CMS database (except in cases where there really is a lot of data, on a news site for example) should not exceed 100 MB at the very most.
- Check the content of comments, which may contain spam, and check the registration settings and the comment approval policy on the site.
Client-side resource optimization
The size of a page, the number of resources loaded, where they come from, the size of images and their compression are all parameters that come into play in a site’s loading speed.
Measuring optimization with GTmetrix
The site https://gtmetrix.com/ lets you analyze in detail your site’s performance from the visitors’ point of view.
Before any resource optimization work, we advise running this test to give you a good idea of what to work on, and also to track the progress of the optimizations you make.
We will detail a few of the most frequent recommendations in this wiki, but the list is not exhaustive and we invite you to complete your research if needed.
Overall page size
Keep in mind that not everyone has a fast Internet connection or a powerful device (mobile or otherwise) to view your site.
- We advise, as far as possible, staying around 1 MB maximum for your page, so that even a 2 Mbit/s connection loads the page in about 5 s.
- If your site is very “graphic” and has large images, you can possibly go up to a page size of 2 MB.
- If you have a photography site, there are no real standards any more, but the ideal is to have a compressed preview of the images and the ability to enlarge the images in good quality.
- If you embed videos, barring exceptions, it is better to use an external site (YouTube, Vimeo, etc.), which will be very good at offering different qualities and compressing the video properly.
Number of external requests
These are requests made when your site is visited, to load resources that do not come from your site. External resources are generally costly in loading time.
They mainly come from themes and plugins that change your site’s appearance, and mostly consist of fonts, JS scripts and CSS.
An external resource means that, for each site hosting a resource, an additional DNS request will be made by the visitor. These requests take a few milliseconds, which added end to end can take a non-negligible amount of time, at least for the first page load.
In addition, external servers may be based far from the visitor’s country, increasing latency and lowering throughput.
You should therefore try to minimize the external resources loaded as much as possible. These are of course flagged by GTmetrix in the “YSlow” section and “Make fewer HTTP requests”, as well as in the “Waterfall”.
Ideally, no external resource should be loaded, but this is almost impossible with a modern CMS. The threshold to avoid exceeding is therefore 30 external resources.
Total number of requests
Each resource generates a small amount of latency. If there are too many different resources, the site is slowed down, particularly on connections with a high ping (latency).
This value is shown at the top right of the GTmetrix test: “Requests”
We advise trying to stay under 100 requests.
Image handling
Image scaling
Wherever possible, try to load into the site only images at the final size at which they will be displayed.
It goes without saying that, for example, using a high-resolution image as a post thumbnail is not optimal: why load an 8 MB high-resolution image when a 128×128 image of a few kilobytes might have been enough?
Fortunately, most CMSs, including WordPress, which lagged behind on this subject for a long time, handle thumbnails and can generate different image sizes and then use the right one depending on the context. However, you need to make sure the theme then uses these thumbnails correctly. If it does not, you need to resize the images manually.
Some plugins offer to do this task: I advise you to back up your files and your database before this operation, which is risky.
Through GTmetrix, this information is found in “PageSpeed”, under “Serve scaled images”.
On VM and dedicated servers, this can be helped by the Google PageSpeed module that can be integrated into Plesk. The module can convert the site’s images on the fly and to the screen size (as long as the images are not too large to begin with). This can be set up by your support and will require you to set up a Google API key for it to work.
Image compression optimization
It is recommended to use a good image compression rate as well as modern formats.
As with scaling, the “PageSpeed” module (VM and dedicated servers only) can help on this point.
Your LRob hosting gives you complete satisfaction. Gain peace of mind with our Webmastering plans.
Discover the WordPress Webmastering plans
Don’t know LRob, the high-performance hosting? It is time to fix that.