Although microorganisms often live in dynamic environments, most studies, both experimental and theoretical, are carried out under static conditions. In this work, we investigate the issue of optimal resource allocation in bacteria growing in periodic environments. We consider a dynamic model describing the microbial metabolism under varying conditions, involving a control variable quantifying the protein precursors allocation. Our objective is to determine the optimal strategies maximizing the long-term growth of cells under a piecewise-constant periodic environment. Firstly, we perform a theoretical analysis of the resulting optimal control problem (OCP), based on the application the Pontryagin’s Maximum Principle (PMP). We determine that the structure of the optimal control must be bang–bang, with possibly some singular arcs corresponding to optimal equilibria of the system. If the control presents singular arcs, then these can only be reached and left through chattering arcs. We also use a direct optimization method, implemented in the BOCOP software, to solve the studied OCP. Our study reveals that the optimal solution over a large time horizon is related to the one over a single period of the varying environment with periodic constraints. Moreover, we observe that the maximal average growth rate attainable under periodic conditions can be higher than the one under a constant environment. We further extend our analysis to conduct a qualitative comparison between the predictions from our model and some recent biological experiments on E. coli. This analysis particularly highlights the mechanisms of action of the ppGpp signaling molecule, thus providing relevant explanations of the experimental observations. In conclusion, our study corroborates previous research indicating that this molecule plays a crucial role in the regulation of resource allocation of protein precursors in E. coli.