Question

I have a website which heavily uses javascript and talks to a .NET C# RPC service. We had issues where clients' browsers cached the javascript so we eventually decided to append version number to the URL to force them to use the latest javascript and that gets round the caching issue. So with every new release we have to create a new application/virtual folder in IIS with the new virtual path. For example:

http://example.com/websiteVersion10

We have a C# web application at the root which redirects requests to the correct latest version from base URL so if someone typed http://example.com, they would get redirected to http://example.com/latestwebsiteversion. The application uses a custom XML config file to read the latest version from which we update with each release.

However we have discovered that clients would bookmark the full 'redirected to' URLs instead of typing http://example.com and when the URL gets outdated because we have released a new version, they would start to get 404 error page unless we kept the old virtual paths in IIS.

Now one way to avoid this is to keep all old virtual paths in IIS and put a redirection page in each outdated website to redirect to the latest version but we do releases quite frequently so I know we will end up with loads of virtual and physical outdated folders very soon.

I tried to use custom 404 error page to redirect from there back to the latest version using something like this:

if(OLD_URLs){
    Response.StatusCode = 200;
    Response.Redirect(LATEST_URL);
}

But that does not work and a blank page is displayed instead.

Is there a neater solution than maintaining all old virtual paths in IIS to achieve this?

Was it helpful?

Solution

If I understand correctly, you are creating virtual directories to ensure you are serving up the latest javascript files?

You should be aware that by appending a new querystring variable to each new version of your script reference, you will perform a cache-bust and the browser will download the latest version:

<script type="text/javascript" src="myscript.js?v=1"></script>

If you update the querystring variable, myscript.js will be re-downloaded again irrespective of what is in the cache:

<script type="text/javascript" src="myscript.js?v=2"></script>

Depending on the version of ASP.Net you are using, you get this for free when you leverage bundles. Bundle up all your CSS and Scripts, set your site to release mode, and ASP.Net will append cache-busting querystrings to your references.

ref: http://www.dotnet-tricks.com/Tutorial/mvc/c72b040113-Asp.net-MVC-4-performance-optimization-with-bundling-and-minification.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top