Query-string in SWF URL is not good idea

Query-string in SWF URL is bad idea because swf would be downloaded again by browser/client instead of being loaded from browser-cache, it happens if URL becomes non-unique due to the presence of changing query-string in different requests.

Browser does cache data for all URL, unless HTTP response headers (for URL or other resources) instruct not to do caching. If URL is different, browser considers it a new requests and downloads the data again instead of consuming from cache.

We can try to avoid or optimize such cases. In past, developers have used the other way by having random (non-unique) query-string in SWF or XML/asset URL to force reloading of asset/resource instead of using the ones from browser-cache. Though, they could have done things by setting right HTTP headers.

I have noticed some websites where swf URL has a query-string i.e. http://yoursite.com/yourapp.swf?var1=somedata, where value of var1 is not constant rather changes? Obvious reason, I want to pass dynamic data most of time hence using query-string instead of hard-coding it in swf itself.

I also noticed some sites which are using SWFObject and still passing data via query-string instead of flashvars using addVariable (..) instance method of SWFObject.

Another place, I again noticed something similar, AVM+ application loads AVM- (SWF 8 or less) application, let’s call it legacy-swf, and passes data via query-string, ok, that is understood there is no other way except writing a light-weight wrapper that uses LocalConnection or query-string approach?

  • It might not be worth writing wrapper in case of small-size legacy-swf but depends, if you are serving to thousands of users, every single HTTP request cost something.
  • If legacy-swf is large enough, it’s worth writing a wrapper that loads the legacy-swf. This way at least legacy-swf would be loaded from browser cache in next session instead of being downloaded again from your server.

This is very basic thing in web-application development, user-experience can be improved by doing these little things. I hope to write some more observations, no matter how stupid/trivial it sounds to me or other programmers. It’s good to post these things in context of flash/flex so beginners, who are not familiar with details of HTTP or other standards, can learn.

Technorati tags: , , , ,

  • Hi Abdul. Something is wrong on this page with the (Google?) add (at least under Safari).

  • @Savvas: Thanks, Safari or some browsers ignore html-comments… I had some code commented in there, I removed it…

  • Thanks for the post — this is a very important observation. Of course every rule has an exception. The one time when it’s good to put a query string on the SWF URL is when you actually *want* it to get thrown out of the cache and redownloaded from the server. Buzzword does this by adding our product build number to the query string of all the SWFs, so that when we release a new version, we can help ensure that we don’t end up in a state where the user has a mix of old SWFs coming from the cache and new SWFs coming from the server. Easy to see this in operation with the Activity window in Safari.

  • I actually use the SWF URL querystring to pass in the application ‘version’ details. And I update this variable everytime there is a new build on the server. Setting the expiry date via HTTP headers wont work because the date of next deployment would be ‘subject to change’ all the time ;o)

  • @Arul: This makes sense, because when version changes that means SWF is also changing right? But what happens, if you are just changing a loadable-module-swf and appending the version to main-app-swf? This might make main-app-swf get downloaded again, which is not necessary?

  • @David: That’s what Arul (commented above) is also doing… It makes sense, though same can be done using HTTP headers (let a php file server SWF for you or write some web-server filter). Combination of conditional-get request, last-modified response-header and if-modified-since request-header (sent by browser to check if content has been modified on server or not)..
    Anyway, in your case build number is constant most of time… As I pointed out above response, build-number is incremented even when your one of loadable-module-swf might have changed and main-app-swf remains same? That’s one place, some optimization can be done..

  • Jessica Koh

    I made a website with a SWF header. The problem is each pages are reloading the same swf from server, not from browser cache.
    This happens in IE and Safari.
    There is no variable in the URL. Just a link to swf.
    Any idea? Thank you.

  • You should try
    => http://flashurl.net/