How does the browser load flash files? Do they load progressively, or does the browser wait until the entire flash file is loaded before displaying it?
The reason is I have a tiny clip that is extremely high in quality, only a few seconds long, but it’s over 4 mb.
Will the user have to wait until all 4 mb is loaded before viewing? Or does it load as the user watches it?
I didn’t do anything fancy, I just imported a .flv into Flash, and exported as a .swf.
Thank you in advanced
There are many parts to loading a flash file, and more generically, an HTML page.
I’m going to start from the top with the HTML page, and I urge others to correct any mistakes I may have made.
Loading a Page
When an HTML page is received, the browser parses it into the Document Object Model (DOM) so that it has a programmatic representation of every element. Browsers iterate over every node in the DOM tree and populate it as-needed.
For most nodes this is simply creating a new DOM element like a
div,p, ora; however some content requires loading or replacement.form elements (
input,select,button,textarea) are replaced with the browser-specific representation of those form fields.linkelements used as stylesheets are asynchronously loaded. The DOM continues to parse the page as the external resource is being loaded.scriptelements on the other hand, are synchronously loaded. The DOM is unable to continue parsing the tree until the script has finished loading and executing, with exceptions for if the loading failed or the execution had an error.imgelements are asynchronously loaded, but allow for theonloadcallback to determine when they have finished loading. The DOM can’t trigger the window’sonloadevent until allimgelements have finished loading (or failed).Understanding the basic elements helps with understanding more involved elements like
object,embed, andiframe, which are also replaced content.Flash is typically embedded on a webpage using
object,embedandiframe.As far as I’m aware,
objectandembedelements react similarly so I will shortcut and sayobjectfrom here on out.There are distinct differences between loading flash in
iframeandobjectelements.The
objectelement is very similar to ascriptelement where the content must be successfully loaded and executed before the DOM can continue to be parsed.The
iframeelement is very similar to animgelement where the contents are loaded asynchronously, but a callback may be used to determine when the loading has finished (although I’m not sure about whether the callback is available for cross-domain requests).Loading Flash
The previous section discusses just the HTML side of content loading. However, there are a number of nuances within flash that can severely affect the load time of a flash movie.
As I stated before,
scriptelements must be fully loaded and executed before the DOM can continue being parsed. A similar effect is found within Flash files (even when included via aniframe). All resources embedded within theswfmust be loaded before theswfcan release its hold on the page loading progress.If you’ve embedded a video directly into the timeline, the entire video must load before flash can be considered done with its initial execution.
If, instead, you chose to use an asynchronous callback to start loading an external resource that happened to be a video, and used an asynchronous loader to load the video, you wouldn’t have to wait for the video to be finished loading before the rest of the page could be loaded; within flash, you’d still need to wait for the video to finish loading before beginning playback of the video.
Alternatively, there are a number of means within flash to either stream videos, or progressively load a video from a server, which would enable the video to be played without being finished loading. My experience with that particular aspect of flash is minimal, so I won’t explain how it’s done.
Using a library like
swfobjectallows the desiredswfto be loaded asynchronously so that flash loading is non-blocking.tl; dr:
Flash files may be loaded progressively depending on how you’ve structured your HTML, and what code is running in the
swf.You may want to look into swfobject