Why does the site take a long time to load on the first visit and between interruptions of page requests
There are times when a site is developed on local hosting and is ready to be transferred to a working hosting, however, on a working hosting, delays in opening pages are visible (the site takes a long time to load) that were not on local hosting. Moreover, such delays are of a variable nature - there are delays during the first visit and after breaks between page requests. What is the reason and how to fix this problem?
The answer to a question can take time even for experienced professionals. Usually, you have to perform a lot of testing operations and study all kinds of site logs to find an answer, but this may not help either. After all, delays began to appear only on a working hosting, and on a local one - everything works quickly.
I must say that there can be many reasons, but the most likely one is poor optimization of database queries or its absence. Such requests generate the transfer of large amounts of data between the site and the database, especially if they are located on different servers. Moreover, both the requests themselves and the amount of processed data slow down the speed.
But why such delays are not visible on local hosting ? Local hosting does not transfer data over the network, so even unoptimized queries and fetching large amounts of data may not greatly affect the speed of opening site pages. The same cannot be said about a website hosted on a network on a working hosting.
Technical explanation - at the first request or with some waiting between requests (for example, 20 seconds), the process responsible for working with the database is re-created - the old process is destroyed and the cache is flushed. If you make requests with a shorter interval, the process does not have time to be destroyed and returns data more quickly, since it has already been created and has all or part of the cached data that needs to be returned.
How to eliminate the delays when opening the site for the first time described above? You need optimize code, responsible for queries to the database. For example, set limits on the number of selected rows from it on each request. Finding slow queries is easy - for example, in the code, you can set in certain places to insert the time code to record the speed and thus search for a slow section of the code. When it is found - perform optimization, and if it is useless - then you can resort to using the cache . It is quite easy to create your own caching system on the site, but that is beyond the scope of this article.
- 09.11.23IT / Database Errors when migrating from MySQL 5.6 to 5.7 and how to fix them - database dump import failed with an error or INSERT does not work. Disabling STRICT_TRANS_TABLES strict mode or using IGNORE
- 09.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes
- 07.07.22IT / Safety How to protect PHP, JS, HTML, CSS source code - obfuscation, minification, compression and encryption
- 06.07.22IT / Safety Connection not secure, problem with Lets Encrypt - how to fix expired 09/30/2021 DST Root CA X3, remove it manually and install ISRG Root X1. Example on MS Windows 7
- 08.07.21IT / Misc How to make a free translation for a website without an API, translate documents in Google Translate