Content Injection in Flash with XHTML and sIFR
Posted on February 23, 2006 in InternetSince we (my team at Digitas) have launched the new Pontiac website using web standards, I have had the opportunity to lift up the hood and explain some of the inner workings to some of the other teams at Digitas.
One of the typical comments we receive is that people love the way that we increased speed and SEO of all the flash objects on the site by using a tweaked script based upon Mike Davidson’s Flash Replacement (aka sIFR).
Mike Davidson’s concept was simple enough -- take a headline (h1-h6) and pass it to a flash movie so you can use flash’s ability to render text in non-standard font faces without having to use 3rd party software (other than Flash) or clunky image rendering scripts.
We took Mike Davidson’s SIFR idea (and script) and expanded on it a little, why does it have to stop with headlines? Why couldn’t we pass multiple elements (paragraphs, lists and links) into a flash movie as XML so that all the content in a flash movie was dormant in the XHTML source. This idea has greatly increased SEO, Accessibility and ease of maintenance because now changing content in flash is as simple as editing XHTML.
Some of the ways this also increased “speed” of our flash is that normally when you utilize XML in flash the load sequence looks something like this.
Server Renders Application page > HTML is Downloaded to the user agent > Flash is initialized by user agent > Flash downloads XML from server > Flash Parses XML and renders movie > Movie is Displayed
All this loading, connecting and parsing takes time as any flash developer will tell you. The size of your XML is directly related to how long this procedure takes.
Using XHTML Content Injection the XML content is already present in the movie on flash load because the content is passed in using querysting values by JavaScript on initialization. Because of this all you need to do is to select the content using your favorite XML parsing utility – we used a mix of XPath and homegrown applications. This load sequence saved us valuable seconds on both the server and client side.
Check out the example on the test demo page, there is a div which has an ID of “flashInjectionExample” on the demo page. This content is being selected by JavaScript which then initializes and replaces the div with the flash movie. That initialization code is placed below -- this calls upon functions which are in the edited sIFR Injection library JavaScript.
<script language="JavaScript" type="text/javascript">
// <!--
var objFlash = getElemRefs("flashInjectionExample");
//var hasFlash = "flase";
if (hasFlash == true){
if(typeof sIFR == "function"){
if (objFlash != null) {
sIFR.replaceElement(named({nWidth:760,nHeight:262,oNodeRef: objFlash, sFlashSrc:"flash/fpo_600x380.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0}));
}
}
} else {
// show our backup content.
if (objFlash != null) {
objFlash.className = "enableBackup";
}
}
// -->
</script>
Download flashInjection_SIFR.js source

RSS (2.0)
Previous Comments
Awesome idea!
How does the raw data that Flash imports work in comparison to the encoded XML (with CDATA)?
Hmm...this sounds great, but for some reason it's not working for me in either Firefox or Safari on Mac...
Actually, I think it IS working for you, you're just not getting the fancy demo you expected. You can select the div text in Flash, which is his demonstration that the HTML content is getting passed to Flash. He's just not doing anything with it yet.
This idea is a cool idea and I have been waiting for a slick code implementation of the idea so it can be used more orelaibly by anyone. However this idea isn't new:
http://wahlers.com.br/claus/blog/seffs-to-flash-or-not-to-flash/
I liked it then too, it just makes sense to keep content in the document and just use flash as a 'presentation layer' so-to-speak.
Hope this gets developed further.
Kev-
On second look, you're right. I stand corrected. Sorry! :)
I would have never thought to use sIFR beyond headlines just for the sake of keeping typography to a standard. But besides that, using it for the bulk of your content (eg paragraphs, and lists etc) seems a bit heavy on client-side overhead.
We use this all the time.
Not SIFR, but our own version developed in Flash. We dont use javascript, just the dynamic field in Flash. The SIFR technique is more search engine friendly.
It allows you to make headings and titles in the font style you like and is great for dynamic sites. The client-side overhead is nothing if you use it once per page, but if you start listing 100 titles per page using it, then watch out, it chunks.
Famous websites that use it include:
www.cbsnews.com
Sorry,
I meant http://www.abcnews.com
@ Dustin's
"using it for the bulk of your content (eg paragraphs, and lists etc) seems a bit heavy on client-side overhead"
I don't think it's a good idea is to create a page full of flash instances for all elements (so on this we agree), instead what I think is a good idea is to pass the entire page XHTML (XML) to one flash instance (using js) and use flash to style that data - therefore you have a fully semantic and presentable XHTML site that is perfectly 'indexable' by search engines and yet you get the benefits of a flash site (should you like flash sites that is). Considering flash's support for css to some degree you could even load the stylesheet after parsing the xml.
Maybe I misinterpreted what the idea of this post was tho.
Hey Guys, Thanks for all the comments.
Dunstan it is a little heavy, but after all our testing on old and up-to-date machines this process seemed to be the least intensive when speaking about time to render and download necessary.
It also greatly increases SEO as Jon B stated.
The sIFR script had a lot of unnecessary elements that we were able to remove and lighten the code therefore increasing its speed. The compressed source is about 15 K and its cached .. which makes the entire experience better than say .. connecting to clunky XML documents in flash on each page load and parsing them.
One of the best things about this script it easily allowed us to pass page content at will to flash pieces which made caretaking after flash as easy as XHTML edits.
There is also a trigger in there if flash cannot be displayed to show the XHTML backup (the actual xml flash source) so we have flash and non flash versions of just about everything that made sense. (360 degree Car spins need not apply)
Check out Pontiac and tell me if you think its "slow" ... ;)
"Why couldn’t we pass multiple elements (paragraphs, lists and links) into a flash movie..."
Because its not a great idea IMO. It didnt improve your SEO more than using regular text.
To be honest here, what is the point?
* Its more work
* It doesnt load as fast (not that its slow)
* Selecting text with SIFR is annoying
* And to top it off the fonts you picked dont really look any different/better than normal text, in fact its harder to read IMO.
The guys who made SIFR said it themselves that it shouldnt be used for more than anything other than headlines.
Jasons:
Once the structure is set up (including a JS) getting this script to replace a div with a flash move is as easy as defining a ID and telling it the movie name. Not that hard. Agreed - nothing is going to be as fast as flat HTML. But when your creative department is trying to get you to do some pretty dynamic things with div boxes, hover states, positioning and rollover images and you have to think of ease of maintenance there is nothing I'd rather use than flash.Working with complex CSS:Hovering and positioning/DHTML is much less preferable than loading a flash movie which actually has better native support than most homegrown JavaScript solutions.
Agreed.Which fonts? On this site. Yeah maybe so -- that comes down to individual taste. What other solution do you have for rendering dynamic text in stylized font faces? Drawing images on the fly? Embedding fonts?
Brand identity is very important to companies and sometimes the Arial, Verdana and Times options just doesn’t cut it.
I am not saying in any way shape or form that this should be used on every piece of flash developed. But where adversity lies maybe this solution may be helpful for some and maybe not.
Either way I appreciate your thoughts.
@Jasons: The point is to serve content to every type of user, regardless of their setup. User that don't have Javascript enabled, users without the Flash plug-in, and users with browsers that don't render CSS (properly or even at all) can all see equivalent content. Sure it's more work, but it's always more work when you want to expand your user-base. The Target.com developers chose to ignore visually-impaired users seemingly because it was more work, and now they're paying the price. It doesn't improve the SEO, but that's not the goal. The technique preserves the SEO, while still delivering content in Flash, an ample solution for one of the inherent problems with using Flash on the web.
"Selecting text with SIFR is annoying... the fonts you picked dont really look any different/better than normal text." Design and methods of working are subjective topics, so opinions will vary. Functionally though, the menu contextually alters the Flash movie, which, without using this alternative, would have required some overkill Javascript. Just speaking in terms of functionality, they seem to have chosen the most appropriate solution.
"The guys who made SIFR said it themselves that it shouldnt be used for more than anything other than headlines." That's probably because their script is tailored specifically to replacing headlines, not other things. As posted in the comment before yours, that's why the script was altered and stripped down.
Dan ..
The raw data is treated just like XML because the modifications that we made to the SIFR script pass it as UTF Encoded XML and we write CDATA tags inside certain elements that we needed.. Look in the raw source inside of a Paragraph element, you should see the CDATA tag in there.
This is Great!
While I have no immediate use for this technique, I can see this is the best approach (so far) for dynamic sites that require some Flash.
"Jasons" let's not stifle the expansion of this or other similar techniques, some other creative genius will take this and build on it and we all will be better for it.
I like the ingenuity of the solution, but the fact that it breaks text resizing completely (not that many sites don't just do it badly) seems like a pretty big stumbling block. I suppose within the Flash movie there could be a font size selector, but nothing beats the ease of Cmd/Ctrl +.
True Matt but that is a basic limitation of flash.
However I would bet that in actionscript if you wanted to you can listen for a CTRL + keypress and change the fontsize.
You could also use an embed technique like FlashObject ( http://blog.deconcept.com/flashobject/ ) to achieve the same end result...
it's just a matter of grabbing the html from inside the div you target and passing it into the Flash movie (something that the sIFR js code makes a bit easier, but still not that tough to do).
If you are using a database, it would also be very easy to simply spit out the html data as well as a separate xml feed. Then the if the flash movie has other variables you'd want to pass in you don't have to include them in your html page.
Here's a quick example I whipped up using FlashObject:
http://blog.deconcept.com/code/passflashxml/flashdata.html
zip file here of the source:
http://blog.deconcept.com/code/passflashxml/passflashxml.zip
Bravo guys. Is this really any more intensive than SiFR? In my informal tests at home SiFR seems to be quite a bit more hard on a slow system. This is such an elegant solution - I can't believe some of the people questioning the use of flash and your technique as somehow inferior to SiFR. It is about experience and that is why its beautiful.
*blinks*
SiF what?
//goes back to the superbowl thread.
Eric -- now that you are famous will you forget all your old readers. Me, Nicole and that lot from Providence? :)
very nice!
content is everything
Eric, someday people will learn that while, yeah, flat HTML is faster, we don't live in an "ideals" world. Some speed is given up for added visual appeal or more design options. Design is about smart, balanced compromises. Great write up.
Brian, Luckily for us, we're not really forgettable. ;-)
Interesting. The Pontaic web site crashes my Firefox v1.5 - Flash Player 8.5.0.212
Must be related to Flash Player 8.5. I reverted back to 8.0.22 and no crashing anymore.
Let me ask one question. How cool was the typeface for headlines on the 2nd to last website you visited? Don't remember? Exactly. Always go for performance on small details when it comes to the web. What seems important to you and I from a compositional point-of-view means squat to your user. What does matter is render time and performance.
Not bashing the technique, I think its great. I am an advocate for flash usage. I just think that after this post/technique was released some follow up on "do's and don'ts when using this techinque" should be posted. Just a little before its time, in terms of browser rendering performance, and implimentation on client's site should be done with EXTREME care. The last thing we need is the next wave of website to be using graphitti fonts for headlines.
Eddie,
This isn’t at all about cool headlines. Its about creating accessible, seo'd documents which have flash in them. This will also allow someone to easily create a flash backup version giving the user additional flexibility on the site to which THEY want to see.
I think we are arguing the same point because as mentioned above this isn’t for everyone. Its meant for someone who has a flash heavy site (for any reason) and would like a way to make that text SEO friendly and accessible.
I was wondering if you had an example of how you got the navigation to import in sIFR? I have some projects that this would really be useful on, and the SEO department loves the idea of being able to update it with a simple CMS.
I just started my Flash class last night, thanks for the info.
fyi: adding amp; after your & in the digg link will get you to 100%, I'm sure it was just an oversight.
Congrats on the Pontiac site, however, I just checked it out and get 3 totally different results:
FF: nothing, i.e. too long to load
Opera: great Flash animation
IE: no animation
No offense (I just started), but the 3 best sites I've seen for Flash are from:
IKEA
C-Ville
Pixel:Gasoline
I have them saved in my http://del.icio.us/BillyG/Flash folder if anybody is interested in checking them out.
Again, thanks for the guidance, it's great to see that Flash is joining the SEO camp, looks like I'm just in time!
This article has inspired me...I have managed to do the sae thing using the UFO Object and some simple Javascript, please have a look here:
http://blog.foozia.com/xhtml-into-flash-through-javascript-xml/
FYI, your "Newport, Rhode Island Sunset" photo has a typo in the caption:
"Newport, Rhode Isalnd Sunset"
it would be nice if your photo header had a reload button so i didn't have to reload your whole site just to see a different photo.
Eric, nice work. The elegance of this approach is great. It seems like there would be a bit of extra dev time, but as you mentioned this will come with the added benefit being easier as well.
Nicely done.
Geoff, thanks for creating the implementation with swfObject and passing along the source files.
This is a great post and a great thread.
Eric, I am for the first time on your site and really pleased to see nice quality work going on here!
in accordance to modern web design standards, XHTML's use is replacing the older HTML
nice article it was very helpful for me
Until now.. this is useful.. though the Pontaic web site crashes
Wow is this ever an old article. Useful, but how do I set up the Flash .swf???
DAESH ONOTOLE V PRAVITELI VSELENNOI!
Nice site, thanks for information!
Not bad... Not bad.
not bad.. but right now there is a new type of SiFr that you can use.. I forgot what is that.. will comeback and post it here again..
Ah my good friend, but you are missing the point that this is more than just headlines. .. Sifr if intended to only replace one headline with a piece of flash text.. this enables full scale flash replacement and passing large segments of XHTML in as source.
See this page for instance.
http://community.som.yale.edu/premba/
The homepage here is 100% flash and its build from the flash backup text. This is there in case you don't have JS enabled, or for search engines. Its basically progressively enhanced flash.
I have seen the new SIFR site and to my knowledge this is not the direction they are heading .. but I feel this is a great plug in for anyone whom is using flash on their site.
Cheers.
I love the creativity behind it this solution and I think it's a very intriguing prospect. However, given that this original post is over two years old, I'm wondering:
1) What (if anything) have people been doing with this technology? Has it developed, evolved, etc. since this original concept was posted? I've Googled XHTML injection and basically all I can find are links back to this original post.
2) What are the advantages of using XHTML injection over SWFObject with alternate content? As far as I can tell, XHTML injection has the one advantage of not having to load additional content, so page loads will be faster. However SWFObject, if paired with SWFAddress, allows you to have deeper, multipaged Flash sites which are deep-linkable, and only hold relevant content to the site (see my post http://tinyurl.com/8z58m5 to see what I'm talking about).
I know I may be talking about and old/expired technology, but in a recent discussion on LinkedIn someone recommended this method as preferable to SWFObject and I just want to better understand why.
Rock on - great post!
--eric