How quickly should a fresh carpet stain be treated?

Ideally within the first few hours, before the spill bonds with the fibres.