Website hosted on home server is very slow but improves on subsequent requests

  apache, http, performance, php

I have a LAMP server which I host my website off of. I used to test the speed of my website. Sometimes I get good speeds (under a second) which is what I want. Then If I test it a minute later, I get between 30 and 32 second load times. My website does not seem to be consistent and I want to know how I can fix it.

When I access my website if I haven’t visited it in a couple hours, it takes very long ( more than 20 seconds for it to load). If I hit the reload button while the page is loading, it suddenly connects to my website. How can I make my website load consistently? The test results are shown below.

Slow Request

In this image, my website takes 30 seconds to wait for What is that and why is the request taking so long. How can I prevent my webserver from connecting to gstatic to speed up the performance of my website?

Test results

Good website speed

Source: Ask PHP