Your goggles get foggy because condensation forms inside the lenses. This is caused either by water vapour or sweat. Foggy goggles can also be caused by a damaged anti-fog coating.
To avoid your goggles from being foggy (assuming the anti-fog coating still works), put them on while they're still dry. You can also use an anti-fog spray to reinforce the coating and repel water from the lenses.