Cache busting best practice?

Jan 25, 2013 at 2:02 AM
Edited Jan 25, 2013 at 2:03 AM

Using, say, the TypeScriptAssetHandler what is the recommendation on invalidating the browser cache? This is often done by including a timestamp of the most recent modification to the linked resource's URI as in the following.

    <script src="app.ts?v=1324819081"></script>

Is there anything that the TypeScriptAssetHandler, the Bundle Transformer, or the System.Web.Optimization libraries do to automate the detection of invalidating changes and generation of the version suffixed resource uri?

I figure I could go the long way of registering a new bundle through the Global.asax, but the simplicity of the TypeScriptAssetHandler is so convenient!

Jan 25, 2013 at 2:15 PM

Microsoft ASP.NET Web Optimization Framework does not add the cache token in debug mode and I can't change this behavior.

TypeScriptAssetHandler created solely to facilitate the process of debugging and can not be used in release mode.

Do you speak Russian?

Jan 25, 2013 at 6:50 PM


Hi Taritsyn,

I regret that I do not speak Russian, sorry.

Thank you for this response.

The documentation and package configuration seems to encourage the use of the TypeScriptAssetHandler without any caveats regarding production use.  Can you please elaborate on this warning?

Further, what do you see as the challenges, if any, in adding a server-side script element tag generator used as follows which for any script root explores and generates cache dependencies on all involved files and gives a timestamped link in the meantime between component file updates.

<%=TypeScriptAsset.CacheSafeScript("~/app.ts")%>  <!-- gives   -->

It seems to me that this would greatly improve deployment smoothness with only a small AppStart performance penalty.

Then in debug mode, CacheSafeScript could output not one bundled, but multiple individual script tags in dependency order so that debugging browser-side remains easy without requiring deployment changes other than debug="true".

Is this a misguided idea?

Jan 26, 2013 at 6:15 AM

Yes, it is a misguided idea. Bundle Transformer - is primarily an extension for the Microsoft ASP.NET Web Optimization Framework. First, learn the possibilities of Microsoft ASP.NET Web Optimization Framework (for example, with the help of a tutorial) and you will learn how to correctly use the Bundle Transformer.

TypeScriptAssetHandler need in order to translate some TypeScript-files, links which appear in the debug mode.