In addition to the space weathering phenomenon described by ebv, optical surfaces can and do get dirtied by other mechanisms as well. In particular, outgassing from the rest of the spacecraft and produce various compounds that may recondense on lenses, especially if these surfaces are cooler than the rest of the spacecraft exterior, which they sometimes are because they are kept shaded to minimize the amount of stray light that gets into the instrument. https://outgassing.nasa.gov/ is the premier collection of data regarding which materials are subject to being volatilized from one part of the spacecraft, then recondensing on another part. These materials are referred characterized by the % amount of raw material that is deemed to be Collected Volatile Condensable Materials (CVCM) and most NASA missions try to severely limit the amount of materials that exhibit a CVCM % of over 0.1%, meaning limiting use of materials where up to 0.1% of the original mass may vaporize and then later condense somewhere else. Some of the worst culprits for contaminating optics are things like rocket propellants, wire insulation, plastic housings for microelectronics, and adhesives and staking compounds.
Some common techniques to minimize contamination on optics besides restriction of construction materials include adding heaters on the optics or designing them to be partially illuminated by the sun safely so that anything that does condense on them can be cleaned off. Also, the layout of the spacecraft can incorporate deliberate design of venting paths to keep plumes of condensable materials directed away from optics and exit the interior of the spacecraft as far away from the optics as possible. Cleaning materials as they are delivered for integration to remove contamination and construction in a cleanroom greatly reduces particulate contamination that can be transferred to optics, although there's always some particulates that get through to the final product. Finally, suspect materials can be preprocessed by baking them out at elevated temperature under vacuum to drive off as much volatile material as possible before integration into the spacecraft. AC Tribble has a nice paper (among many others he's written) describing some of these techniques in detail: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19960044619.pdf
In addition to the particulates that may contaminate optics during construction, testing, transport and the launch environment can all deposit additional particulates on optical surfaces and a contamination budget and plan are usually developed for sensitive optics to ensure sufficient mitigation is employed to allow the instrument to meet cleanliness requirements. These mitigations can include temporary covers that may be removed before flight or potentially opened after launch, sometimes a few days or weeks after launch to allow as much contamination to leave the spacecraft before exposing the sensitive optics. Once in space, the local contamination environment from particulates and volatiles rapidly improved in an exponential decay fashion, thus most of the contamination that does occur, happens early. How fast this decay happens is a function of how well vent paths are designed in the satellite. If only small openings are present and the path to the outside is tortuous then outgassing the majority of material can take weeks or months. Sometimes if semipermeable coatings are used like conformal coatings on circuit cards, they can slow the release of volatiles from plastic parts or other sources and also delay contamination. A discussion of the pros/cons of this approach as a deliberate tactic are discussed here: https://hlinstruments.com/RoHS_articles/Evaluating%20conformal%20coatings.pdf
So, to answer the question directly, I'd have to amplify what ebv says and concur that the contamination rate of optics depends very strongly on the design of the spacecraft and the elements mentioned above.
One final source that sometimes gets forgotten is radiation darkening of materials. This is a bit different than the weathering since it can occur below the surface of the optics. Various materials including glasses, plastics, and especially adhesives used in the construction of optics are susceptible to a drop in transmissivity after exposure to radiation. Clear quartz turns to smoky quartz in the ground due to exposure to natural background radiation, and quartz windows in optical instruments do the same in space. On the CYGNSS spacecraft UV and radiation exposure lead to a marked loss of sensitivity on some of the optical sensors on board, resulting in up to a 20% degradation of the signals in the first month of operations. Luckily the system rapidly stabilized after that, but for a time there was a danger that the spacecraft could be partially blinded, resulting in a chance of loss of the vehicle if safe mode was triggered.