You know how your immune system reacts to a virus, but there's a spool up time? Your body also reacts to vaccines, in a more mild fashion, in a way that reduces the spool up time.
Think of it this way. In Afghanistan, someone shoots at guys on the ground, and it takes time to PID, get coords, program a weapon, etc. But it you know where Bin Laden is hiding, with a picture of the guy, already know what's in the building...you can react much more quickly.
Vaccines are like an Intel shop for your immune system, priming it to react to threats before they enter the body.