Third-party code is all the scripts from other sites and more precisely from CDN (Content Delivery Network) that can be directly integrated into the page. These scripts are in most cases essential to the proper functioning of the page. They are used, for example, to analyze traffic, provide sharing buttons for social networks, set up advertising, etc.
Third-Party scripts bring a set of useful features to websites but their use can also degrade the page performance if they are numerous and not optimized. The aspects that can be impacted are :
Beyond a blocking delay of 250ms caused by third party code, it is necessary to intervene and reduce its impact on page performance:
<script src="https://cdn.example.com/script.js" defer></script>
function load(event) { event.target.removeEventListener(event.type, arguments.callee); var script = document.createElement('script'); script.src = 'https://cdn.example.com/script.js'; document.head.appendChild(script); } document.getElementById("bouton").addEventListener("click", load);
<script src="https://cdn.exemple.com/script.js"></script><script src="/js/script.js"></script>
<script src="https://cdn.exemple.com/unused.js"></script>
<link rel="preconnect" href="https://cdn.example.com">