Why is networking slow to start up after exiting the screensaver? For the past month, networking on my iMac has had strange behavior after waking up from the screensaver. For example, the first website that I visit in Google Chrome (after exiting the screensaver) displays an error page at first:

There is no internet connection
...
ERR_INTERNET_DISCONNECTED


Then, if I don't touch anything, a few seconds later, the error page refreshes and the browser connects to the website normally. This didn't used to happen. Safari does it too.

Afterward, all web browsing and networking are normal, until the next time the Mac sits idle and the screensaver activates. Then the behavior repeats.

I've also noticed that incoming network connections have a similar symptom. The first time I "ssh" or use a VNC client to connect to this iMac (after the screensaver has kicked in and some hours have passed), it takes many seconds to connect, but a second connection attempt is instant.

Anybody know why this happens and how I can fix it?

This is MacOS 10.12.6 with the latest Google Chrome.
It could be that when asleep your wifi become disconnected. When you then try to connect the 1st time it thinks there is no connection. After a few seconds, the wifi is restored and pages load. I don't know how to prevent it from disconnecting. I'm still working on that.