Initializing embedded content after a page has loaded
Most Twitter for Websites integrations will be well served by the recommended embed code found in the set-up documentation, but you may want to optimize how and when the Twitter for Websites JavaScript widgets scans the page DOM to discover new HTML elements eligible for enhancement into buttons or widgets.
If content is dynamically inserted into a page (such as lazy-loading content or using a pushState technique to navigate between articles) it’s necessary to parse new buttons and widgets using the twttr.widgets.load() function.
twttr.widgets.load()
Called without argument, widgets-js will search the entire document.body DOM tree for uninitialized widgets. For better performance, pass an HTMLElement object to restrict the search only to children of the element.
Example:
twttr.widgets.load(
document.getElementById("container")
);