Almost all contemporary swim goggles come with an anti-fog coating on the inside of the lenses. How long this coating lasts depends on how you treat the goggles--the more you use them and the more you touch the inside of the lenses, the more quickly the coating wears off. Once you notice traces of fog developing inside your lenses, you have two options: Either refresh the anti-fog coating regularly or invest in a new pair of swimming goggles. A few quick-fix remedies do exist, but they're not as effective, nor as long-lasting, as a spritz of anti-fog spray.
Avoid touching the inside of your goggles. If they need to be cleaned, just rinse them with fresh cool water. This will help preserve the anti-fog coating most goggles come with; as long as the coating is intact, your goggles will stay fog-free. Once the coating starts to wear off--this is natural, and how long it takes can vary enormously--you'll start to notice traces of fog inside your goggles.
Refresh the anti-fog coating inside your goggle lenses with a quick spritz of anti-fog spray the minute you notice fogging. It only takes a tiny bit of spray to restore the anti-fog coating, so a bottle of anti-fog spray will last you a long time and can even be shared with friends, making it a much less expensive alternative to replacing your goggles.
Splash a bit of water on your goggles, then tip them over to let the water drain out just before swimming, if you don't have any anti-fog spray handy. Some swimmers also swear by spitting in their goggles, then rinsing them clean with water, to prevent them from fogging. Since anti-fog spray usually works so well, these should be last-minute stop-gap options for use only if there's no anti-fog spray available.