The electronic properties of Cerium (Ce) and ytterbium (Yb) intermetallic compounds may display a more local or more itinerant character depending on the interplay of the exchange interactions among the $4f$ electrons and the Kondo coupling between $4f$ and conduction electrons. For the more itinerant case, the materials form heavy-fermions once the Kondo effect is developed at low temperatures. Hence, a temperature variation occurs in the electronic structure that can be traced by investigating the optical conductivity ($sigma(omega)$) spectra. Remarkably, the temperature variation in the $sigma(omega)$ spectrum is still present in the more localized case, even though the Kondo effect is strongly suppressed. Here, we clarify the local and itinerant character in the electronic structure by investigating the temperature dependence in the $sigma(omega)$ spectra of various Ce and Yb compounds with a tetragonal ThCr$_2$Si$_2$-type crystal structure. We explain the temperature change in a unified manner. Above temperatures of about 100 K, the temperature dependence of the $sigma(omega)$ spectra is mainly due to the electron-phonon interaction, while the temperature dependence below is due to the Kondo effect.