JQuery $(document).ready() problems when external ad-script is slow to load
I have a site that contains several ad zones. Some are javascript includes, others are iframe includes. The javascript includes are placed right before our closing tag, and the iframes are scattered around the page.
Today, I was developing locally with no internet and noticed that my javascript inside of document.ready() doesn't run until all of these external assets are loaded or time-out. This exposes a vulnerability, because if an ad server goes down (out of my control), that could make the page unusable.
What are the 开发者_StackOverflow社区best practices to work around this problem?
For the javascript includes, look into a script loader like Yepnope (which is also built into Modernizr, which you may already be using). For the iFrames, could you insert them into place in your page via JS after DOM-ready? Perhaps using empty divs with the same size and replacing them with the required iFrames with jQuery/JS?
精彩评论