views:

426

answers:

3

When a swf is embedded in a page and is not cached locally in the browser, two requests for the swf are fired by the browser. Here is a simple example.

The first request returns an expected 200 OK, and the second request triggers a 304 Not Modified after the first request has completed, indicating the file is now cached locally.

Why is this 2nd request fired and how can I prevent it?

+1  A: 

I just verified that this happens for me, as well.

At first, I thought this was due to a bug with Firefox. See FAQ question #16 on this page. The bugs they reference appear to be fixed, however.

So then I looked at some of my own web sites that embed SWFs using SWFObject 2.2. The double-GET did not occur. I think the difference is that in my code, I'm calling swfobject.embedSWF in the <head> of the page instead of the body. Putting the script in the head is what the SWFObject 2.2 documentation recommends (this is a bit of a departure from older versions of SWFObject).

So here's what I'd try if I were you:

  1. Remove the google.load("swfobject", "2.2") and include the SWFObject script directly.
  2. Move your swfobject.embedSWF code into the head of your page.
Jacob
Even with this updated example which includes swfobject directly and invokes the embed call in the document's <head>, I still see the double request.http://www.dweebd.com/examples/double-swf-request/embed-in-head.html
Duncan Beevers
+1  A: 

I think I figured it out. I read the bug reports for Firefox more carefully, and this looks to be caused by AdBlock Plus, which I have installed. First, I verified that the bug still occurs with your updated page, and reproduced it a second time. Then, I disabled AdBlock Plus and tried the same test. The double request was no-longer happening. So if you have that extension installed, or perhaps a similar extension, that may be the cause.

This is the bug report about the plugin being double-instantiated, and this is the bug report for the fact that AdBlock Plus causes it.

Jacob
I think if you're only seeing one request you may simply have a cached swf. Have you verified that the one request you're seeing is a 200 OK? I see double requests and do not have AdBlock Plus (or any weird plugins installed)http://www.dweebd.com/examples/double-swf-request/no-weird-plugins.png
Duncan Beevers
Which version of Firefox are you using?
Jacob
+1  A: 

I believe this can also be triggered by running Firebug - try checking your browser requests using LiveHTTPHeaders (or some other http sniffing app like Charles) while you have Firebug disabled.

Geoff
Disabled firebug and only a single request was fired.http://www.dweebd.com/examples/double-swf-request/single-request.png
Duncan Beevers