On the compactness of minimizing sequences of variational problems