  A conservative constraint on the rest mass of the photon can be estimated
under the assumption that the frequency dependence of dispersion from
astronomical sources is mainly contributed by the nonzero photon mass effect.
Photon mass limits have been earlier set through the optical emissions of the
Crab Nebula pulsar, but we prove that these limits can be significantly
improved with the dispersion measure (DM) measurements of radio pulsars in the
Large and Small Magellanic Clouds. The combination of DM measurements of
pulsars and distances of the Magellanic Clouds provide a strict upper limit on
the photon mass as low as $m_{\gamma} \leq2.0\times10^{-45}~\rm{g}$, which is
at least four orders of magnitude smaller than the constraint from the Crab
Nebula pulsar. Although our limit is not as tight as the current best result
($\sim10^{-47}~\rm{g}$) from a fast radio burst (FRB 150418) at a cosmological
distance, the cosmological origin of FRB 150418 remains under debate; and our
limit can reach the same high precision of FRB 150418 when it has an
extragalactic origin ($\sim10^{-45}~\rm{g}$).
