Friday, December 19, 2008

Isolating 3rd Party JavaScript

I'm looking for a way of protecting our web pages from 3rd party javascript files that might timeout or throw errors. These files are usually for ads where we just include a script reference.

What makes it worse is that these files contain code that does a document.write(). Because of this, moving the reference or trying to load the file asynchronously will cause the ads to be rendered on a different part of the page. Because of the use of document.write(), the only way to load the files without affecting the page's load time is to load them from within an iframe.

In addition, we can override on the onerror event for the page in the iframe.

This method scares me since I really can't imagine what would happen if other developers start putting this little snippet of script into all their pages. In addition this sounds like a whole lot of extra work just because some other companies product is problematic. Stop using their product is what I think.

No comments:

Post a Comment