In this paper, we focus on a particular application of the nanomechanical resonator: mass sensing in all-optical domain. Convectional mass detection is usually based on the electrical environment, where nanomechanical resonator should be suspended between two electrodes above a conducting plate, while a voltage applies on them. However, the heating effect and the energy loss induced by the voltage during the measurement will lead to the imprecision of mass sensing. In order to solve this problem, we propose an ultrasensitive optical scheme to weigh the external particles deposited onto the surface of the nanomechanical resonator via all-optical methods. This optical mass sensing has the potential to break through the limitation of frequency restriction and the sensitivity of mass sensing.