Patrick Hulce gathered information from both desktop and mobile versions of popular websites on which he experimented programs written in the Javascript. This technique is typically used by developers to make any website interactive. It also helps to display ads or logs to the user’s click.
Hulce also found out that the Javascript code helping Google place ads on pages and analyze user activity bestowed the most extended delays on visitors. Mr. Hulce told The Register news site that the Javascript used by Google to show ads and its analytics system was found on the most significant number of websites in a million sampled. If these are used together on a site, it can add more than two-thirds of a second to the loading times, he found.
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.
There were also some ad-serving scripts written in Javascript, which imposed longer delays but were used on a much smaller proportion of websites.
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.
A primary goal of the recent redesign of NYTimes.com article pages was to improve page load speed and perceived performance. Ads usually load JavaScript files, which blocks the browser from loading other data until the script finishes executing. Combining that with the fact that ads are typically placed near the top of the page and have a recipe for a lot of blocked loading that will slow things down.
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.