Shock at night and keep your pH in check.
Yes, you can prevent most cloudiness. The two main culprits: shocking during daylight and unbalanced pH.
Shock breaks down in sunlight. If you add it during the day, half the power is gone before it’s done its job. Add it after sunset, run the pump overnight, and give the filter time to catch the dead stuff.
The other common mistake: pH too high or too low. Ideally, your pH should be between 7.2 and 7.4 before you shock. If it’s off, the shock reacts weird and forms calcium carbonate precipitate — that’s the white cloud.
Also, don’t over-shock. More is not better. Follow the label for your pool size.
A little cloudiness for a few hours is normal. If it’s still milky the next day, your filter might need a backwash or you have a calcium hardness issue. But do the basics first.