(Screened) hybrid functionals are being used more and more for solid-state calculations. Usually the fraction alpha of Hartree-Fock exchange is kept fixed during the calculation; however, there is no single (universal) value for alpha which systematically leads to satisfying accuracy. Instead, one could use a property of the system under consideration to determine alpha, and in this way the functional would be more flexible and potentially more accurate. Recently, it was proposed to use the static dielectric constant epsilon for the calculation of alpha (Shimazaki and Asai 2008 Chem. Phys. Lett. 466 91 and Marques et al 2011 Phys. Rev. B 83 035119). We explore this idea further and propose a scheme where the connection between epsilon and alpha is optimized based on experimental band gaps. epsilon, and thus alpha, is recalculated at each iteration of the self-consistent procedure. We present results for the bandgap and lattice constant of various semiconductors and insulators with this procedure. In addition, we show that this approach can also be combined with a non-self-consistent hybrid approximation to speed up the calculations considerably, while retaining an excellent accuracy in most cases.