Klaus Nji
Klaus Nji

Reputation: 18857

Visual Studio 2012 not picking up latest compiled TypeScript for ASP.NET MVC4 project

How do I force Visual Studio 2012 to always use the most recent version of the generated JavaScript file created by TypeScript?

I am using the following definition in my project file:

<Target Name="BeforeBuild">
    <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -out scripts\app.js scripts\app.ts  -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" IgnoreExitCode="true" />
  </Target>

When I clean and rebuild the project, app.js is updated accordingly.

However, for some strange reason, when I try to debug the solution using Internet Explorer, Visual Studio is using an outdated version of app.js, which invalidates my breakpoints.

What is going on here?

Upvotes: 2

Views: 1323

Answers (1)

Fenton
Fenton

Reputation: 251012

The most likely problem here isn't really TypeScript or JavaScript - Internet Explorer is just caching the JavaScript file and using the out-dated version.

If you are referencing an individual script, you can cache-bust it by changing an arbitrary part of the URI:

<script src="myscript.js?1"></script>

If you increment the 1 each time you want to replace the cached version, it will cause the new script to be loaded. You could automate this by dumping a timestamp in place of the 1.

If you are using bundling, which I recommend in MVC4, the bundler will append a hash of the scripts, which does the same thing.

Upvotes: 4

Related Questions