Machine learning offers the potential to revolutionize the inverse design of complex nanophotonic components. Here, we propose a novel variant of this formalism specifically suited for the design of resonant nanophotonic components. Typically, the first step of an inverse design process based on machine learning is training a neural network to approximate the non-linear mapping from a set of input parameters to a given optical system's features. The second step starts from the desired features, e.g. a transmission spectrum, and propagates back through the trained network to find the optimal input parameters. For resonant systems, this second step corresponds to a gradient descent in a highly oscillatory loss landscape. As a result, the algorithm often converges into a local minimum. We significantly improve this method's efficiency by adding the Fourier transform of the desired spectrum to the optimization procedure. We demonstrate our method by retrieving the optimal design parameters for desired transmission and reflection spectra of Fabry-Pérot resonators and Bragg reflectors, two canonical optical components whose functionality is based on wave interference. Our results can be extended to the optimization of more complex nanophotonic components interacting with structured incident fields.