- General When Flash means no cache | Cactus

When Flash means no cache

You just love them : these flash files are heavy, uncontrolable, resist any attempt to replace it with something lighter, and they seem to pop out on every single godamn page. Well, maybe you don't like them so much but Bill and Brenda at marketing do : it increases their sales, spices up their pages and makes them all the more important.

What you have to love is how most flash files don't seem to go into the cache of browsers. It gives you an occasion to think about things are done and apply all the advice you read here.

I have recently come across such an occasion. A web page contained an incredible amount of mobile phones (88), and even several flash animations for events that had occured over the weekend. The same, 46 KB flash animation, downloaded different 12 times, thus accounting for more than 600K.

Why so much hate? Well that's because the flash developer had parameters to give to the flash file. And to do so, he used the scr url. When you want to give parameters to Flash files, you can put them as cgi get parameters, thus using urls such as flash.swf?id=12345&cache=absolutely never.

What the http 1.1 mechanism of your web browser does is recognize that the url of the resource is different, thus requesting a different representation of the same resource.

Of course you should use cache directives to ask the browse to cache. A cache-control: max-age=3600 is a sound directive to add in the headers of the files as you send them. Check your local web server to see how things are nice. Unfortunately, this won't be of much use in the case we describe. As all requests are different, you'd have to come back to the same page to see this in action.

What you definitely need to do is get your flash developer straight. Using urls is old school. Since Flash 6, you can use flashvars to do such a thing as passing parameters. It means that you can pass different parameters for each flash file, and give the exact same url for the source flash file. Flashvars are easy to use, available on both the active X and the plugin. Even swfobject enforces flashvars.

So next time you decide to add Flash files in production, make sure during your tests that no parameters are passed.

if you're the Flash video kind of guy, I advise you to go check what limelight or akamai can do rather than try to serve 50 simultaneous users (50 at 150 kb/s is 7.5Mb/s).

Publié le 25 Oct 2007
Écrit par Cyril Godefroy