With fresh swelling it's important to remember the acronym RICE.
"R" stands for Rest, but generally this doesn't mean being a couch potato, but means Relative Rest meaning be fairly active, but respect your pain and don't be active to the point of aggravating your swelling,
"I" stand for Ice. If the swelling has been caused by an injury within 48 - 72 hours then always ice rather than heat. Ice reduces blood flow to the injured area by vasoconstriction (narrowing the arteries temporarily). This reduces the leaking of the extracellular fluid, which contributes to swelling. Swelling slows down the bodies recovery from injury by reducing range of motion, increasing pain sensitivity, reduced joint awareness (balance and proprioception) and causes scar tissue if swelling remains for too long.
Compression is "C" and is often not considered by many people with swelling. However it's probably the most effective intervention especially when the compression is applied for long periods. Forms of compression include Ace bandages and compression sleeves like Tubigrip. After knee and ankle surgeries compression socks are often prescribed too. The compression should be firm, but not uncomfortable and certainly shouldn't affect circulation to the point where fingers or toes become blue.
"E" is for Elevation. Elevation involves having the affected leg lifted up in a relaxed position. It's most effective when lying flat with the limb elevated over a pillow or two so that the limb is above the level of the heart.
Post surgical knee and ankle patients often complain of increased swelling once they go back to work especially in sitting jobs where there legs are not elevated. Gravity pulls the swelling back down into the legs. It is important to take regular breaks from sitting. About once a hour get up from your desk and move around. While sitting elevate your leg as much as possible like on a stool or trash can.
A common complaint is that ice is uncomfortable. So when can you switch from ice to heat? If the swelling has been there for longer than 3 days then up you can start to consider heat rather than ice. However if the heat increases your swelling then switch back to ice. After surgery however the surgeon might insist on a longer period of icing than 3 days.
This is not intended to be specific medical advice, but rather is intended to be informative and educational.