We theoretically analyze the response properties of ultracold bosons in optical lattices to the static variation of the trapping potential. We show that, upon an increase of such a potential (trap squeezing), the density variations in a central region, with linear size of ≲10 wavelengths, reflect that of the bulk system upon changing the chemical potential: hence measuring the density variations gives direct access to the bulk compressibility. When combined with standard time-of-flight measurements, this approach has the potential of unambiguously detecting the appearance of the most fundamental phases realized by bosons in optical lattices, with or without further external potentials: superfluid, Mott insulator, band insulator and Bose glass.