The query string v has a value token that is a unique identifier used for caching. As long as the bundle doesn't change, the ASP.NET application will request the bundle using this token. If any file in the bundle changes, the ASP.NET optimization framework will generate a new token, guaranteeing that browser requests for the bundle will get the latest bundle.
Why a server check ?
Browsers use a freshness heuristic to determine if they should validate a resource with the server or just pull it from the cache.
The browser will serve cached files without validating them with the server unless one of the following is true:
- The freshness heuristic is not met (that is, the file in the cache is not considered fresh).
- You have changed the expires header or other caching header.
- You have set the browser to disable caching..
- The URL to the resource changes or is different.
Adding a Web.config file to the Scripts folder:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseExpires"
httpExpires="Thu, 01 Jan 2016 00:00:00 GMT" />
</staticContent>
</system.webServer>
</configuration>
This sets the Expires Header out for a year. this will allow your files to be served directly from the cache without checking with the server for the next year.
As for bundles, headers are explicitly set inside System.Web.Optimization.dll
:
private static void SetHeaders(BundleResponse bundle, BundleContext context)
{
if (context.HttpContext.Response != null)
{
if (bundle.ContentType != null)
{
context.HttpContext.Response.ContentType = bundle.ContentType;
}
if (!context.EnableInstrumentation && context.HttpContext.Response.Cache != null)
{
HttpCachePolicyBase cache = context.HttpContext.Response.Cache;
cache.SetCacheability(bundle.Cacheability);
cache.SetOmitVaryStar(true);
cache.SetExpires(DateTime.Now.AddYears(1));
cache.SetValidUntilExpires(true);
cache.SetLastModified(DateTime.Now);
cache.VaryByHeaders["User-Agent"] = true;
}
}
}
so you need to check that you are not breaking any of the rules forcing the browser to check with the server!
references:
Update
If your target is to have your scripts always emitted as:
<script src="/Scripts/printarea/jquery.PrintArea.js"></script>
<script src="/Scripts/pagedown/Markdown.Converter.js"></script>
<script src="/Scripts/pagedown/Markdown.Sanitizer.js"></script>
<script src="/Scripts/pagedown/Markdown.Editor.js></script>
Rather than:
<script src="/bundles/textview?v=cNvP0r6Jo6hsl2Sdzhw-o3kAK7t2JdcNWiG0iIg7Lys1"></script>
Then add the following to the RegisterBundles
method (disabling Bundling and Minification):
BundleTable.EnableOptimizations = false;
Unless EnableOptimizations
is true
or the debug attribute in the
compilation Element in the Web.config file is set to false
, files
will not be bundled or minified. Additionally, the .min version of
files will not be used, the full debug versions will be selected.
EnableOptimizations
overrides the debug attribute in the compilation
Element in the Web.config file