The code putting ads on web pages can stop pages loading by seconds, finds analysis of millions of sites
Not all the delays caused were down to ads and analytics, said Mr. Hulce. Other factors like big file sizes and network delays for some content could also contribute to slow loading times.
Hulce said that the greater use of ad-blocking programs may not always improve browsing speeds. Ad-blockers can sometimes end up triggering complex disguising of ads, which drastically increases script execution time and convoluted workaround logic. Using ad-blockers may not be the best way to avoid delays and speed up the loading of web pages, he added.
About 60% of the total loading time of a page was caused by scripts that place adverts or analyze what users do, he found.
Embedding the ads directly into the HTML allows the script tags included in the ad to block rendering of the pages, slowing the speed drastically down. However, there should be a better way to defer the loading ads without involving their functionality.
PostScribe from Krux battles this problem using a simple method they refer to as “DOM Proxies,” which attempts to resemble the way the browser creates HTML via document.write. It inserts each ad into the body of a dynamically created iframe after the DOMContentLoaded event fires. Every iframe has its document object so that any document.write calls made in the ad will only be applied to the frame’s document and not to its main page, solving the document.write’s concern. Since people don’t need to prevent ads from busting out of their frames once they have loaded, they can use iframes as a transparent drop-in solution. This allows users to load ads after the page has already finished loading.