We explain how to compactify the moduli space of vector bundles on a smooth projective surface X. Maps into the this moduli space correspond to families of bundles on X and we generalize this notion by introducing a concept of quasi-bundle, or bundle with singularities on a (non-fixed) finite subset of X, so that families of quasi-bundles is compact in a certain sense. Although our results give a counterpart of the Uhlenbeck compactness theorem in analysis, our methods are completely algebraic and based on a recent work of V. Drinfeld on infinite-dimensional vector bundles. When X is the projective plane a related construction was given by Finkelberg, Gaitsgory, Braverman and Kuznetsov.