Note that the Manchus took over, over two centuries after the Ming moved the capital to Beijing, because they were brought into a civil war. Then it was over another two centuries before barbarians sacked Beijing. They approached from the sea, so having the capital at Nanjing wouldn't have helped.
Militarily, the Chinese dynasties in fact did better when the capital was close to the frontiers (various iterations of Xian in the west, Beijing in the North) as opposed to away from the frontiers (Loyang, Kaifing, Nanjing, Hangzhou). However, the cause and effect in this instance was that the dynasties that paid more attention to having a strong military preferred to have their capital where the armies were, while the more pacific minded dynasties had the capital where it made the most economic sense, or were forced to put the capital in the south because they had lost control of the north.
The closest analog of a continental size non-Chinese empire moving its capital to the frontiers is the Russian relocation of the capital from Moscow to St. Petersburg, but that also made considerable economic sense. Once they started getting into really serious wars they moved it back. During the Roman Empire the center of administration tended to migrate to places that were more strategically located than Rome was, but still central, with the Emperors moving to the frontiers when they were conducting wars.