Contents
Introduction to optimization
The slowness of a website significantly reduces the time spent by visitors on it. Optimizing your site's speed is therefore a major factor not to be neglected.
Contrary to popular belief, a slow site is not necessarily due to the slowness of the server hosting it. Of course, an overloaded or poor-quality server can cause slowness, but LRob does its utmost to eliminate this possibility.
Against this backdrop, we've found that the vast majority of requests for slow website performance are due to a lack of site optimization, hence the usefulness of this article. (Nevertheless, if your site is unusually slow, don't hesitate to contact your support team to ask for a check).
Optimization can be divided into two main parts:
- Resources loaded by site visitors
- CPU resources used by PHP and MySQL on the server during page loading
Optimizing server resources
The loading time of a page on your site is directly linked to the computing power required to generate it. It is therefore important to ensure that the PHP code generating the pages is as optimized as possible to deliver the correct loading time.
What's more, a poorly optimized site can, in extreme cases, slow down an entire server. If, for example, each page leads to very long MySQL requests (over 20 seconds), and the site receives several visits per second, the server's CPU utilization can quickly reach 100% and performance will degrade dramatically, or the server may even stop responding.
It's also 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 times won't be any faster with 8 cores than with 2 cores if there's only one visitor, but on the other hand, you'll be able to accommodate more visitors simultaneously without slowdowns.
The following optimizations apply to all CMS (WordPress, Joomla, etc.)
Common mistakes to avoid
To save you time, let's start with the leads that will only waste your time and should therefore be avoided.
- Multiply plugins: Most plugins load on every page, slowing down your site a little more each time. What's more, some may conflict with each other, and the addition of numerous plugins multiplies the risk of encountering bugs.
- Use cache plugins (WPSupercache, WPRocket...): Caching systems can generate numerous problems and dynamic pages, if they still work, will remain slow. The problem must be tackled at source, rather than using a palliative that is generally far less effective than real optimization.
- Keeping a site out of date with an outdated version of PHP: In addition to the dramatic security problem involved, you're potentially reducing your site's performance by a factor of 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're using the latest supported version of PHP (adjustable via your Plesk control panelEvery new version of PHP since PHP 7.0 has improved performance.
Plugins and extensions
- As far as possible, limit the number of plugins/extensions/modules installed, as each module is an additional source of slowdown.
- Check that you don't have any plugins or modules that require too much performance. Deactivate all modules, check the site speed, then gradually reactivate them to find the plugin(s) slowing down the site. The same 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 or other logs, find a way to clean it up periodically (via the backoffice, via a plugin, or via PHPMyAdmin for example).
- The database of a CMS (with a few exceptions where there is a lot of data, for example on a journalistic site) should not exceed 100MB.
- Check the content of comments, which may contain spam, and check the site's registration settings and comment acceptance policy.
Optimizing customer resources
The size of a page, the number of resources loaded, their origin, the size of images and their compression, are all parameters that come into play in the loading speed of a site.
Optimization measurement with GTMetrix
Le site https://gtmetrix.com/ provides a detailed analysis of your site's performance from the visitor's point of view.
Before any resource optimization operation, we recommend that you carry out this test to give you a good idea of the elements to be worked on, and also to monitor the progress of the optimizations made.
We are going to detail some of the most frequent recommendations on this wiki, but the list is not exhaustive and we invite you to complete your research if necessary.
Overall page size
Bear in mind that not everyone has a fast Internet connection or a high-performance device (mobile or other) to view your site.
- As far as possible, we advise you to keep to a maximum of 1MB for your page, so that even a 2Mbit/s connection will load the page in around 5s.
- If your site is very "graphic" and features large images, you may want to go up to a page size of 2MB.
- If you have a photography site, then there aren't really any standards, but it's ideal to have a compressed image preview and the possibility of enlarging images in good quality.
- If you're inserting videos, with a few exceptions, it's best to use an external site (YouTube, Vimeo, etc.), which will be very good at offering different qualities and compressing the video as required.
Number of external requests
These are requests made when visiting your site, to load resources that don't come from your site. External resources are generally expensive to load.
They come mainly from themes and plugins that modify the appearance of your site, and contain mostly fonts, JS scripts and CSS.
An external resource means that for each site containing a resource, an additional DNS request will be made by the visitor. These queries take a few milliseconds, which together can take a considerable time, at least for the first page load.
What's more, 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 indicated by GTMetrix in the "YSlow" and "Make fewer HTTP requests" sections, as well as in the "Waterfall".
Ideally, no external resources should be loaded, but this is virtually impossible with a modern CMS. The threshold to avoid exceeding is therefore 30 external resources.
Total number of requests
Each resource generates a small latency. If there are too many different resources, the site is slowed down, especially on connections with a high ping (latency).
This value is shown in the top right-hand corner of the GTMetrix test: "Requests".
We advise you to try to stay under 100 requests.
Image management
Image scaling
As far as possible, you should try to upload images only at the final size at which they will be displayed.
It goes without saying that, for example, putting a high-resolution image in the thumbnail of an article is not optimal. Why load an 8MB high-resolution image when a few kilobytes in 128×128 might have been sufficient?
Fortunately, most CMS - including WordPress, which has long been a laggard on this subject - manage thumbnails and are capable of generating different image sizes, then using the right one depending on the context. However, it's important to ensure that the theme then uses these thumbnails correctly. If this is not the case, images need to be resized manually.
Some plugins offer to perform this task: I advise you to back up your files and database before performing this risky operation.
Via GTMetrix, this information can be found in "PageSpeed" under "Serve scaled images".
On dedicated VM servers, this can be aided by the Google PageSpeed module, which can be integrated into Plesk. The module can convert site images to screen size on the fly (provided the image size isn't too large to begin with). This can be set up by your support team, but you'll need to set up a Google API key to make it work.
Image compression optimization
We recommend using a good image compression ratio and modern formats.
As with scaling, the "PageSpeed" module (VM and dedicated only) can help here.
Related pages :