With page speed being a factor in the rank of your website on Google, tracking the load time of your web pages may be something you create an event out of. And Google is not the only reason you should know how long it takes your pages to load. There is a method behind the Google algorithm. Visitors don't like slow pages. They want their content now. After all, they could just search again and find another page that doesn't waste a whole five seconds of their time.
This is going to require an extra bit of JavaScript though. We will be using the JavaScript Date()
method to generate a timestamp at the top of the page. And then at the bottom of the page, by using the window.onload
JavaScript event, we will wait for the page to load before we create another timestamp. We will use the difference in these two timestamps to calculate the load time of the page and save this as a custom variable.
<html> <head> <script type = "text/javascript"> var page_load_start...