Destroy your iFrames
When you run a site with ads, it can be like running Chrome with too many tabs open. You’re likely loading lots of hidden iFrames. To keep your site sane, it’s important to do something when these frames have outlived their use.
What is an iFrame?
An iframe is effectively a page within a page. It loads a specified url, which can come from any third party. Each iframe includes a separate layout engine, event system, and javascript heap, everything a different tab in your browser would. You can imagine this can get pretty performance heavy.
Despite their performance issues, iFrames can quite good for isolation, particularly if sandboxed. They can’t read content outside of themselves, which is why they’re used so predominantly for third party content like ads.
Hidden Data
While iFrames are originally intended to be viewable on the page, because of their isolating properties, they’re very typically used by third party tools to manage their own data. These iFrames are hidden from view typically by setting their width and height to 0 and/or using “display: none”.
But how necessary is this data? To understand this better, let’s examine a particularly predominant use of hidden iFrames: “usersync” frames.
Advertisers use usersync frames to sync anonymized identifier cookies with other partners. Company A knows you as "user123" while Company B knows you as "user789," and they need a way to realize these IDs refer to the same person.
Your browser loads the iframe from the ad exchange’s domain
The ad exchange reads its own cookie (e.g., “user123”) from your browser
The iframe redirects to the partner’s domain
The partner reads their own cookie (e.g., “user789”) and creates a mapping: exchange_id=user123 ↔ their_id=user789
Both companies now know these IDs represent the same user
You can typically identify them by their sandbox parameters:
sandbox=”allow-scripts allow-same-origin”
The thing is, this process is typically finished fairly quickly. Unfortunately, these frames aren’t cleaned up automatically after they’ve served their purpose. You can do this yourself fairly easily however.
Have your page wait ~60 seconds, then use some classic jQuery to search for the signatures and remove them.
You can use the sandbox parameters above to identify usersync frames.
As for the rest of them, it’s tricky to say what every third party is doing in these iFrames (this is partly the point!) so, mainly this must be approached through experimentation.
In my experience, I’ve observed no ill effects in the data from simply cleaning up every hidden frame. On the flip side, this has had incredible effects on memory usage for longer running pages, reducing the load by 40%!
So, what are you waiting for? Smash your iFrames today!

