Will embedding an advertisement slow down my website?
I've worked with a dozen advertisement networks and this is how they all want you to embed an ad on your website.
<html>
<body>
<div id="ad">
<script type="text/javascript" src="ad.js" />
</div>
<div>
The rest of my site
</div>
</body>
</html>
Some of my personal code waits on the DOMContentLoaded event and some waits on the window.onLoad event. If these events get delayed because of the ad, my site will appear slow to the user.
As the HTML is being parsed, does DOM construction halt as it hits the <script>
tag? Will the browser wait while ad.js is being loaded before continuing to construct the DOM? If so, DOMContentLoaded will be delayed.
The ad inserts images at the location of the script tag. If the images take a long time to load, will window.onLoad be delayed? Is window.onLoad only delayed by static images already engrained in my 开发者_StackOverflowHTML or is it also delayed by dynamic images inserted by the script tag?
First of all, why not load the ad after the dom has been loaded? You could leave your page load normally, then just bind a function which injects the ad.
Also, have a look at the defer
attribute on the <script>
tag. Setting it would the ad a lower priority in the page execution in regards with other scripts and resources being loaded. Even though it's not a cross browser solution it's not to be ignored.
http://www.websiteoptimization.com/speed/tweak/defer/
yes, it will be delayed since javascript execution is a blocking action. you could try putting your ads in the bottom of your HTML and then moving them via absolute positioning in CSS or maybe even moving them around with some JS of your own.
Placing your script just before </body>
will not slow down your page load. Your page will still load normally. All <script>
placed before </body>
and after your HTML will load last. This is the way yahoo recommends it. Read the yahoo blog for Speeding Up Your Web Site http://developer.yahoo.com/performance/rules.html
精彩评论