  We study the frequency dependence of the optical conductivity $\text{Re} \,
\sigma(\omega)$ of the Heisenberg spin-$1/2$ chain in the thermal and near the
transition to the many-body localized phase induced by the strength of a random
$z$-directed magnetic field. Using the method of dynamical quantum typicality,
we calculate the real-time dynamics of the spin-current autocorrelation
function and obtain the Fourier transform $\text{Re} \, \sigma(\omega)$ for
system sizes much larger than accessible to standard exact-diagonalization
approaches. We find that the low-frequency behavior of $\text{Re} \,
\sigma(\omega)$ is well described by $\text{Re} \, \sigma(\omega) \approx
\sigma_\text{dc} + a \, |\omega|^\alpha$, with $\alpha \approx 1$ in a wide
range within the thermal phase and close to the transition. We particularly
detail the decrease of $\sigma_\text{dc}$ in the thermal phase as a function of
increasing disorder for strong exchange anisotropies. We further find that the
temperature dependence of $\sigma_\text{dc}$ is consistent with the existence
of a mobility edge.
