Twitter embedded not rendering from database


I’m using /statues/embed api to get the HTML for twitter embedded timeline. I extracted the html bit and saved to MongoDB for caching. However, once the pages is loaded, if I put this code at the bottom of the page sometimes it worked most of the time it didn’t. I also tried to put the script at the header results were the same.

How do I ensure that the widgets.js will work all the time?