Blogroll

As to continue my previous post, these days I’ve been trying to provide a solution that removes the ambiguity for the released swf files into production so that I know what version is deployed and also to make sure that the users are forced to get the last release, no matter of their browser’s cache.

Problem
When deploying new versions of the application, some users having cache in their browser don’t see the updated version of the swf, thus loosing the updates.

Solution
Automatically append the version number at the end of the url pointing to the swf file, ending with something like : Main.swf?173-1.0-SNAPSHOT. The advantage is that you benefit of the cache in-between new releases; this means that clients can view you flash application faster, and only for new releases they have to wait a little bit more to load.

Having the flex application packaged inside of a WAR file I’ve been looking for places to store this information inside of it, and read the build-number at runtime. I discovered that the MANIFEST.MF file, which is found inside the META-INF folder, is the best candidate.
In order to write the buildNumber into that file, I used maven-war-plugin:

${BUILD_NUMBER} is only available when executing the maven build from Hudson, as explained in my previous post. Maven also has a plugin that generates a build number automatically, but I didn’t need it because, in my case, no code goes into production without passing the Continuous Integration build and the tests, so I will have a build number for every promoted build.

Next, I had to read the information at runtime. For that I altered a bit the index.jsp file I am using to show the flex application:

and it’s set automatically, for each build. This ensures that users, testers, everyone else see the right version of the application.

Note that I’m also using the Specification-Version, which is the same with maven version. The reason I’m doing this is because locally, on the dev machine, the ${BUILD_NUMBER} is null, and I simply didn’t want to see Main.swf?null in the url :). Specification-Version came for free with the Maven-war-plugin, so I decided to make use of it. The MANIFEST.MF file contains more information; you can have a look into that file, after deploying it.