Archived topic
Advice for third-party code lazy loading?
5 replies · Started by Andy on November 24, 2020
Hi there,
After installing some third-party Ad code (javascript), I noticed my site takes a huge hit on speed tests. Google recommends: "Third-party code blocked the main thread. Third-party code can significantly impact load performance. Limit the number of redundant third-party providers and try to load third-party code after your page has primarily finished loading."
Do you guys have any advice on how to load javascript Ad code after my page finishes loading? I'm sure I can find something online. But, I'm wondering if there are any methods/plugins that work well with GenereatePress?
Thank you
Hi there,
Where are you adding the code currently?
Hi Leo,
1 - sidebar
1 - body of a single post
1 - maybe in a floating banner at the bottom of the screen
Thank you
Like you added Javascript directly into those places?
If so there is no way around it unfortunately.
Usually Javascript goes into wp_footer with a hook element:
https://docs.generatepress.com/article/hooks-element-overview/
And it would be the last thing to load.
Ok brilliant! I'll try that! Thank you Leo
No problem :)