thuansaritasa / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

Slow ad servers delay the DomContentLoaded event (and thus, delay the createSWF() function) #328

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use SWFObject in 'dynamic publishing' mode.
2. Link to swfobject.js in the HEAD element of the Web page and also call 
the embedSWF() function inside the HEAD element of the Web page.
3. Place ad server JavaScript snippets at the end of the Web page to make 
ads load at the very end of the page (after everything else on the page).

What is the expected output? What do you see instead?

The expected output is exactly what happens. The JavaScript for the ads 
load JavaScript files from remote slow ad servers. So, the DomContentLoaded 
event fires only after the JavaScript files for the ads have been 
downloaded and parsed. As a result, the createSWF() function is only called 
at that time and to a user visiting the page, it looks like the Flash 
elements on the page have to wait for the ads.

Is it possible for the createSWF() function to run before the 
DomContentLoaded event fires? Should there be an option to call the 
embedSWF() function right underneath the alternative content (instead of in 
the HEAD element) and immediately call the createSWF() function since the 
alternative content is already in the DOM (and we are sure it won't get 
modified later on before the DOM is completely loaded)?

What version of the product are you using? On what operating system?

SWFObject 2.2. Windows XP and Windows Vista. Multiple browsers.

Please provide any additional information below.

Original issue reported on code.google.com by david_be...@yahoo.com on 20 Jun 2009 at 6:24

GoogleCodeExporter commented 9 years ago
Can you show an exact example of where this happens?

As far as you can tell, did this also happen with previous versions of 
SWFObject?

Original comment by bobbyvandersluis on 22 Jun 2009 at 9:03

GoogleCodeExporter commented 9 years ago
Hi Bobby, thanks for the quick reply.

As far as I can tell, the issue I’m describing above is not a bug with 
SWFObject. 
It’s more of a feature request.

As I understand, SWFObject (in 'dynamic publishing' mode) waits for the Web 
browser’s 
'DOM loaded' event before doing its thing (executing the createSWF() method). 
This is 
the expected behavior and works just fine.

However, since we started displaying ads on our website (www.telequebec.tv), 
the Web 
browser’s 'DOM loaded' event takes a lot longer to fire (since the Web 
browser must 
now wait until all the JavaScript files for the ads have been downloaded and 
parsed 
before it can fire that event). And most ad servers are dead slow…

I would like to know if SWFObject could be configured to do its thing 
(executing the 
createSWF() method) before the Web browser has fired its 'DOM loaded' event. 
That 
way, my Flash files would not have to wait until the JavaScript for the ads 
have been 
loaded before they can be displayed by SWFObject.

Maybe something like this…

<div id="myFlashFile"></div>
<script type="text/javascript">
  swfObject.createSWFNowEvenIfDOMNotLoadedYet();
</script>

I’m not sure but didn’t FlashObject 1.5 work that way? Did FlashObject 1.5 
use to 
wait for the Web browser’s 'DOM loaded' event to do its thing?

I understand that manipulating the DOM before it has fully loaded might not be 
completely safe in all cases. But in most cases (as in my example above), we 
can 
assume that the DOM node that needs to be replaced by a .swf file will not be 
modified later on by some JavaScript so we could theoretically modify it right 
after 
it has been declared in the HTML and not have to wait until the 'DOM loaded' 
event is 
fired.

Original comment by david_be...@yahoo.com on 22 Jun 2009 at 2:31

GoogleCodeExporter commented 9 years ago
You cannot dynamically add elements to a Web page before the DOM has loaded 
(read:
the structure of a Web page has loaded, excluding images, SWFs, an other 
external
assets). So what you request is not really possible.

Also, I think that the problem you are encountering is that browsers generally 
refuse
to do any further rendering of a Web page until they have received a requested
Javascript file, in your case a script from a slow ad server that is added 
in-page.
One solution to solve this is to use iframes instead, so the adds and their 
scripts
will be loaded independently of the main page. Only restriction you have here 
is that
iframes have a fixed width/height.

Furthermore, if you use static publishing (regular markup) your SWF will start
loading as fast as possible (milliseconds before the DOMContentLoaded kicks in 
and
dynamic elements are inserted), so that will give the fastest performance 
loading-wise.

Original comment by bobbyvandersluis on 23 Jun 2009 at 9:43