Website hosted on Mac taking too long to load on the first access

I'm using an old Macbook Pro (2011) to host a few websites. Everything works fine, but after a long time without hitting the server the websites take a really long time to load (even in my local network) and I can't figure out why.

I imagine that it has to do with the machine entering in a sleep state, or something similar, but that's just a guess.

Any idea of what could be happening?

Things I already did

Turn off Put hard disks to sleep when possible (Preferences->Energy Saver)

Some extra info:

  • macOS version: 10.13.3
  • Server software: Caddy
  • Disabling the sleep mode: InsomniaX

Solution 1:

Take a look a my question over here How to prevent Safari from stopping downloads?. I would mark as an exact duplicate but it is not the same question, only the same answer. The problem that what is occurring is your computer has to wake up from sleep. "But wait InsomniaX is supposed to prevent it from sleeping!" Yes it is. But it does not seem to work in this case.

Since you do not want specific times for the server to wake and sleep I would suggest these settings.

System Preferences>Energy Saver

Computer Sleep: Never

Put Hard disks to sleep when possible: Unchecked

Wake for WiFi Access: Checked

Then open a new Terminal.app in /Applications/Utilities/Terminal.app and enter the following command: caffeinate and leave it running.

You can also create a LaunchDaemon so that caffeinate will start automatically on restart.

P.S. I too use my MacBookPro 2011 as a server. I use it with macOS Server to host websites, file server, VPN, and others. Great use for an old computer.