开发者

How to preload external JS file with ads?

Is it possible to preload a external JS file, so that the generated JS content appears first on page? I'd like to assure that my ads are already loaded when the page is shown to the user. Right now there is a small 开发者_开发问答delay when loading ads from external JS, while the page content is already visible.


To answer this question I must know how the ads are being loaded. Some external JavaScript ad-loaders attach themselves to the load event of the DOM itself, which means they will not fire until the entire document has loaded. If you have control of the ad loader JavaScript, you could inject it into the DOM earlier, either by dropping the <script> into the location where it should end up in the body or by finding an event that happens before the document is completely loaded (which is dicey if the JS needs to use the DOM).

Either way, you're beholden to the time it takes the server to respond to the request for that JS and the time it takes the browser to process and render the result. In other words, you're taking an asynchronous request and forcibly making it synchronous, or "blocking".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜