2.19.3. Site optimization
There are several ways to increase the performance and speed of the site:
- Website optimization:
- Website optimization (scripts, pages, etc.).
- Usage hosting capabilities to optimize the site.
- Server software optimization (for VPS and dedicated servers).
- Increased resources provided:
- Thechange Business hosting tariff plan to a higher one.
- Increasing the power of the VPS server or moving to a higher tariff (for VPS and dedicated servers).
Website optimization is not in vain ranked first, because it has the highest priority among the rest.
If we take two completely identical servers with the same configured software and place them on the same site that uses an unoptimized theme, plus 2-3 dozen plugins that have not been tested by anyone in terms of load and interaction, and on the other the same site, but using caching of ready-made pages , with the critically necessary minimum of plugins / modules optimized among themselves, it turns out that the second server, even without performing other points, can work 2-4 times faster (in some cases everything is much more dramatic and the acceleration after competent optimization of the site is dozens of times) and create less load than the first.
From the site
In this article, there will be no specific recommendations for changing the script code to improve performance due to the complexity of implementing universal solutions for each control system. All actions for setting up and changing the site must be done independently or involve third-party specialists from the field of site development for this.
Of the simplest areas of optimization, the following stages can be distinguished, concerning almost all popular CMS:
- Disclaimer of plugins and additional modules — all kinds of plugins, modules and extensions that seemingly expand the functionality of the site, in very many cases — its enemies in the context of performance. There are a lot of reasons for this. The main one — many modules are written by enthusiasts and are of very low quality both in terms of consumed resources and in terms of conflict—free with other modules and CMS... Therefore, before adding a new module or plugin, think about whether it is possible to implement the same functionality without it? If not, after installation, test it in detail under load, see how resource consumption has increased, read reviews from other users.
- Refusal from stolen and low-quality themes and plugins — oddly enough, this is also an important point, since in 8 cases out of 10 the hacked product, contrary to the assurances of hackers, remains not only dangerous in terms of possible "bookmarks" and backdoors, but also much more problematic in terms of resource consumption. "Self-written" the same components and themes in the overwhelming majority of cases are of very poor quality. Avoid them if possible. If low resource consumption is important, do not use "universal" themes. Due to the use of various additional frameworks such "harvesters" work slower and consume more resources.
- Caching pages with scripts — this method allows you to generate site pages in advance and save them in static files, which will be transferred many times faster. It is worth using the saving of pages by site scripts to files wherever possible. The return of a pre—formed page of the site spends much less resources and time than generating it for each new visitor "from scratch"... This method is one of the most effective due to the use of static pages.
- Optimization Database and requests To her... When using the majority CMS one of the most important points is the optimization of the database and queries to it, since it is used to store almost all the data required for the correct operation of the site and the generation of pages. Many sites can be slow only due to problems with storing data in the database and unoptimized queries to it. That is why TTFB can grow and the time for processing requests can increase.
- Appeals to third-party sources... Loading data from other servers can be a huge problem in the speed of loading pages or generating them. There can be a huge mass of reasons for problems in loading resources, but the most frequent and resolved on the site side are:
- The remoteness of the server to which requests are made. The further away the target server is located, the longer it takes to communicate with it. This is expressed in slow page generation by scripts due to the fact that they are waiting for a response from a remote server and, as a result, in slow page loading in the browser, quite often — freezing at some stages "renderings" pages (this is clearly expressed with consistent slow loading of parts of the page — first headers, then, after some waiting, loading the rest of the content).
- The target server is unavailable. If the server with which you want to communicate is not available, then there can be a huge problem in the speed of loading and page generation. If the problem occurs on the backend side, then the page can be empty for a long time and only when the connection process is reset — the page can be displayed (most often this is a disconnection, which in the framework of virtual and business hosting will occur 3600 seconds after the start of the connection), it will seem that the site is not working.
- To solve such problems, we recommend:
- Use CDN services for the required resources, if possible.
- Minimize remote storage of resources. This can be done by storing the necessary resources in the site directory, thereby increasing the stability and speed of the site.
- Use asynchronous resource loading (using
defer) that are not involved in content generation or are of little importance. For example, counters, advertisements, and more.
- Minimize calls to third-party resources from the backend and, if possible, set a specific timeout for functions that make connections (for example, using
- Reducing the number of requests to the server... When loading a site, in the case of a lot of uploaded files, there may be problems in the speed of its loading or even in the form of errors. Hosting has certain restrictions on the number of simultaneous connections, and therefore errors may appear. But even if there are none, then a lot of requests will affect the site's loading speed. Each file creates a separate connection to the server, the process of initiating the connection and all other stages for the correct transfer of data also takes a certain amount of time, which creates delays in the site loading speed. If you compare two identical sites, but one contains 150 downloaded files, and the second contains the same data, but already in 50 files, then you can notice a significant increase in the speed of its display.
To solve this problem, we recommend:
- Reduce the number of uploaded files on the site by rejecting unnecessary elements or by uploading them after certain events (for example, page scrolling, button activation, etc.).
- Combine possible files into one or more. If you use several CSS-files, in some cases they can be combined into one to save the number of requests and improve compression. Some plugins or components, as well as functionality, can automatically perform such actions. Pagespeed... But it is extremely important to make sure that the site is working correctly when using these optimization tools.
- You should not use asynchronous loading of resources everywhere, since if on a site where 50 resources are loaded, asynchronous loading is set for all files, then this will generate 50 simultaneous connections with one call to the site, which can create not only difficulties in the form of errors from the outside server due to restrictions on simultaneous connections, but also on the side of the client who opened the site, since all simultaneous requests also create a rather high load on the browser side.
- Website resource optimization... When loading the site, problems may arise that the layout itself is loaded quite quickly, but the elements of the site are loaded for a very long time, everything freezes and so on. Most often, this problem occurs when large site resources are not loaded correctly. For example, images with a very high resolution are loaded for the mobile version at once in high resolution, or a lot of JS scripts with a huge amount of data are loaded. There are various technologies that can speed up the loading of data, for example, some of them:
- Lazyload (lazy loading) — the essence of the technology lies in the fact that when the page is opened, not all images are loaded, but only those that fall into the scope. The rest of the images are tweaked by the browser dynamically as the page scrolls.
- Optimizing image size... Due to the effective compression of images, you can achieve a significant increase in the speed of loading pages.
- Using images in WebP format. This format has gained popularity due to less "weights" relative to other formats without loss of image quality.
- Lazy loading of scripts. For the most part, some site scripts are not needed before it is generated, so loading them first is meaningless. For the site to look extremely fast, the visual component of the site must be loaded first, after which only all the dynamic content should be loaded. Due to such a change in the loading order, you can achieve a visual acceleration of the website loading.
- AND another very effectivebut a time consuming and not always possible way is to avoid scripting wherever possible. The fastest site is a site consisting of a set of static files. One of the options for such an implementation is the use of content management systems (CMS) forming exactly the set HTML-files (of course, the administrative part itself CMS it may well consist of scripts). An example of such CMS may be Movable Type.
From the hosting side
Within the framework of hosting, you can make certain settings that to some extent can help in optimizing the site's performance, but they should not be perceived as a universal tool for all occasions, since this or that technology may not bring the expected efficiency. Most of the recommendations of the settings on the hosting are focused on using caching of data and pages for subsequent transfer to the client without re-processing the request by scripts and generating pages again. The principle of data caching allows you to reduce the amount of data transferred between scripts or servers, reduce the number of scripts processed, etc., thereby greatly speeding up the generation of a response. This method is quite useful for fixing the problem with high TTFB... It is important to consider that not for everyone CMS it is possible to customize all the specified optimization methods.
- Enabling caching (Memcache(d))... The use of Memcache (d) in different systems is organized in different ways, in some it is used exclusively for storing data transferred from databases (which allows you to save on the time of transferring a request to the database, searching for the required data and transferring the request back), in some it is used to cache specific pages of the site (which is more efficient in terms of speed, but less convenient in terms of generating dynamic content)... It is worth noting that the behavior of caching data in memory Memcache (d) is specified directly in the site scripts.
- Setting up caching Opcache... Using Opcache saves you a lot of time by saving the compiled bytecode of your scripts. This method is extremely useful if you use a lot of unchanging scripts that can take most of your time. Unlike Memcache (d) – Opcache can be simply connected to the site without the need for additional configuration.
- Using the data warehouse Redis – in its own likeness, this method is similar to using Memcahce (d) due to the fact that they both save data to RAM and then allow it to be used for faster access, the logic of the behavior of saving data and other things is also similar.
- Using optimization opportunities PageSpeed... The PageSpeed optimization module is installed on the hosting by default and all its capabilities are available for any site. To some extent, most of its settings can be dangerous for the operation of the site due to the fact that the names of the loaded scripts, the principle of their loading, etc., are changed, depending on the included parameters, but as one of the optimization methods – it can be considered to speed up the loading of content. It is important to understand that in order to reduce TTFB (response time from the server) this method will not work at all, since it is aimed at improving the generation of pages in the client's browser and loading the site's resources.
- Caching static content... An extremely useful fundamental feature for speeding up the loading of web pages is caching the pages themselves and the resources connected to them. It is important to pay attention to the fact that such caching is performed not on the server side, but on the client side, and therefore the first loading of the site will be unchanged, but subsequent page transitions or entries to the site can be much faster and not noticeable at all, with the correct organization of the site and caching.
How can I speed up my website?
Website optimization is carried out exclusively by specialists from the field of website development. Hosting does not have the ability to perform such optimization and provide specific recommendations for each situation.
Is it possible to speed up the work of the site by changing the tariff?
Shared hosting tariff plans work on the same servers, so changing the tariff is unlikely to help.
If tariff plans are used businesshosting, then it is worth looking at the current load curves to the server — if they observe the limit indicators of resource consumption, then change of tariff plan higher may help in solving the problem.