[en] We introduce a nanomechanical platform for fast and sensitive measurements of the spectrally resolved optical dielectric function of 2D materials. At the heart of our approach is a suspended 2D material integrated into a high Q silicon nitride nanomechanical resonator illuminated by a wavelength-tunable laser source. From the heating-related frequency shift of the resonator as well as its optical reflection measured as a function of photon energy, we obtain the real and imaginary parts of the dielectric function. Our measurements are unaffected by substrate-related screening and do not require any assumptions on the underling optical constants. This fast ($\tau$rise∼135 ns), sensitive (noise-equivalent power = 90 pW/√Hz), and broadband (1.2-3.1 eV, extendable to UV-THz) method provides an attractive alternative to spectroscopic or ellipsometric characterization techniques.