On the one had it is as you said, as a preventative measure to head off infection (which is obviously very bad), but it's worse than that - industrial farmers use antibiotics so they don't have to inspect and treat each animal. Just dump antibiotics into their food and if they are injured somewhere along the way it will hopefully heal on its own. Inspecting and treating each animal individually would be a lot more expensive.
The other reason antibiotics are given to livestock is to cause weight gain. If the antibiotics cost less than the value of the extra meat produced, then you make more money.
It's a fucked up practice that we'll be all pay for in a few decades.
Note the wiki page is an ok source, but is in need of some attention from someone outside the industry.