In the modern age of the web, speed is key. Gone are the days when you opened a web page, and went outside for twenty minutes before coming back to find that the web page is almost finished loading. Even if there are still people on dial-up connections, the modern world demands speed.
In the past, one of the best ways to improve speed was to reduce the size and amount of the components of the webpage. More specifics of this are outlined in an older LC article about decreasing page load time.
But when we’ve done all we can to reduce page loading time, we can still optimize further by locating and removing/optimizing bottlenecks in the code.
WordPress pages are all dynamically generated, meaning that they are recreated every time someone opens a page. Dynamically generated pages have many pros and a few cons. One of these cons is that it takes time to generate the page before sending it to the user, whereas static pages are immediately sent.
While many dynamic pages are coded in a way that allows them to be generated very quickly, sometimes blocks of code can take more time than intended or thought. This can lead to webpages taking a very long time to generate. Fortunately, there is a way to identify these blocks by adding small bits of code into WordPress.
WordPress has a function called
timer_stop(). What this function does is that it returns the amount of time, in seconds, that has passed between when the server started generating the page to the time that the function was called.
For example, the following code:
<!-- <?php echo timer_stop(); ?> seconds passed. -->
would produce the number of seconds passed in an HTML comment.
timer_stop() can be called as many times as you want in WordPress’s code, which becomes useful for doing the following:
<!-- <?php echo timer_stop(); ?> seconds passed. --> // Fast block of code <!-- <?php echo timer_stop(); ?> seconds passed. --> // Slow block of code <!-- <?php echo timer_stop(); ?> seconds passed. -->
Let’s say this produced the following numbers: 0.01, 0.05, 0.32.
By matching up the numbers to the positions of the code, I could then determine that the slow block of code took .27 seconds to generate, while the fast block of code took only .04 seconds.
By using this method, you can identify bottlenecks in your WordPress code and remove or optimize them to make page generation faster.
Hope this helps you make your WordPress installation faster.