ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified)

force browsers to get latest js and css files in asp net application
asp.net bundle cache busting
mvc clear bundle cache
asp net bundle optimization
asp net bundle config
bundleconfig.json not working
ui bundling
scripts render not working

I am trying out ASP.NET Bundling with ASP.NET MVC 4 application. The situation is that I want to make a CDN style service, which has JS and CSS files to which you can address from other sites with this type address: http://www.mycdn.com/scripts/plugin/js, which bundles and minifies all included .js files.

My bundle config for one file looks like this:

bundles.Add(new ScriptBundle("~/Scripts/plugin/pluginjs").Include("~/Scripts/plugin/jquery.plugin.js"));

However, when I do this, the bundles are not getting updated even after I change the original js files. I keep on getting 304 Not Modified, when I refresh my browser, and the content of the minified file is not updated. How can I make bundles update, because it is useless to have bundles with old content? I tried out every way, but could not figure out a solution.

Thanks in advance!

Adding Cache-Control headers to Static Files in ASP.NET Core, ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified) - asp.net. I have an ASP.NET MVC4 application that (I think) has been working correctly with JavaScript and CSS bundling since it was first published one year ago. During that period, we have published numerous updates and seen no evidence of problems with script delivery.

ASP.NET Bundling - Bundle not updating after inclu, Note that this is not the only way to add cache headers to your site. If it hasn't changed, the server will send a 304 - Not Modified response, and the has expired, or after the browser evicts the files from its cache, we'll be back to You can use this approach by updating any references to the file in your� That’s the reason the bundle was not rendering in the first place. After adding bundles.IgnoreList.Clear() the default MVC ignore list got cleared and the .min extension file started rendering. Clearing the ignore list is not the correct way of using the bungle. It will be always good NOT to include .min.css extension files in the bundle as

Okay, here's my story. I disabled generation of min files for less files in Web Essentials. Old min files were not deleted, and bundle thingy saw those instead of updated CSS. Good luck!

EDIT

Sometime later I spent another good 2 hours on the same issue. This time it was my fault I guess - I forgot the leading tilde, i.e. I wrote

Scripts.Render("/js/script")

in lieu of

Scripts.Render("~/js/script")

For whatever reason it sometimes worked, and sometimes it did no such thing.

MVC4 bundling CSS failed Unexpected token, found '@import , ASP.NET Bundling - Bundle not updating after inclu. 混吃等死 关注 which bundles and minifies all included .js files. However, when I do this, the bundles are not getting updated even after I change the original js files. I keep on getting 304 Not Modified, when I refresh my browser, and the content of the� I have no idea why this would be the case since that minified file is not referenced anywhere (even after the view updated) and shouldn't even be considered since the code is set to not be optimized. This is most likely a bug (or a feature) of the bundling functionality.

Please note that if you are using Google Chrome the caching is quite aggressive. To ensure nothing is cached, you can do Ctrl-Shift-I to bring up the developer pane. Go to Network and click Disable Cache. Ensure you keep this open. Now refresh the page. Your cache should be cleared and the file changes should be reflected now.

Bundling and Minification, In my Global.aspx.cs Application_Start I have the following: However, when I view the source of my bundles CSS file, it has the following: is not use *.css, and instead explicitly list what jquery ui files you want to include: NET Bundling - Bundle not updating after included file has changed (returns 304 not modified)� ASP.Net MVC Style Bundle Not Including Most Files. By default, files with names ending in ".min.css" will only be included in release builds.The recommended bundle configuration is to only include non-minified .css and .js files, then the .min version will be automatically selected (if it exists) in release builds, i.e. <compilation debug="false">in your Web.config.

I actually decided to not to use System.Web.Optimization for this task, but I found Microsoft Ajax Minifier, which is also included in WebGrease.dll, which comes with MVC4 System.Web.Optimization library. I wrote the following function, which I then called in Application_Start for each minified file:

    public static void MinifyFile(string virtualPath)
    {
        string fullPath = HttpContext.Current.Server.MapPath(virtualPath);
        string extension = Path.GetExtension(fullPath).ToLower();
        string targetPath = fullPath.Substring(0, fullPath.Length - extension.Length) + ".min" + extension;
        if(File.Exists(fullPath) == false) 
        {
            throw new FileNotFoundException("File not found: " + fullPath);
        }
        string input = File.ReadAllText(fullPath);
        string output;
        if (extension == ".js")
        {
            Microsoft.Ajax.Utilities.Minifier jsmin = new Microsoft.Ajax.Utilities.Minifier();
            output = jsmin.MinifyJavaScript(input);
        }
        else if (extension == ".css")
        {
            Microsoft.Ajax.Utilities.Minifier jsmin = new Microsoft.Ajax.Utilities.Minifier();
            output = jsmin.MinifyStyleSheet(input);                
        }
        else
        {
            throw new NotSupportedException(extension + " is not supported for minification.");
        }
        File.WriteAllText(targetPath, output);
    }

Now, my application is minifying all files on Application_Start.

Understanding HTTP/304 Responses, Bundling and minification are two techniques you can use in ASP. NET 4.5 that makes it easy to combine or bundle multiple files into a single file. file is set to debug="true" ) because the JavaScript files are not bundled or minified. Include ( "~/Scripts/jquery-{version}.js")); // Code removed for clarity. ASP.NET 4.5 has it built in in the ASP.NET WebForms Template. Here are the steps how to achieve the Bundling. Here are the steps how to achieve the Bundling. Create a new Project and add a ASP.NET Web-form Application by selecting the below template in your visual studio.

Website performance: How I've improved the performance of this , A web server sends a HTTP/304 in response to a Conditional copy is the latest —if so, it sends back the HTTP/304 Not Modified headers, sent by the browser, a hint that the user has hit F5 to refresh the page. After clearing the browser's cache, go back to Fiddler and check the NET � JavaScript� Additionally, the browser requires a validation request for each asset. In this case, bundling and minification provide a performance improvement even after the first page request. Bundling. Bundling combines multiple files into a single file. Bundling reduces the number of server requests that are necessary to render a web asset, such as a web

[PDF] Fast ASP.NET Websites, Indeed, your JavaScript file may not be valid anymore if a single character changes after the decompression. Whereas an image is still valid and� asp.net - mvc - bundling in asp net ASP.NET Bundles how to disable minification (10) I have debug="true" in both my web.config(s) , and I just don't want my bundles minified, but nothing I do seems to disable it.

Fink Flatow, NET Web Forms application 54 This book would definitely not have been possible without Chapter 5 explains the new bundling and minifying features built into ASP. because you might be profiling a web page that's been updated on the server but isn't Figure 4.4 A repeat request for a CSS file which returns a 304.

Comments
  • see stackoverflow.com/a/34508048/1545567 for a possible answer to that problem (i.e using a bundle from another site or from plain html)
  • Touch both normal and minified files and it'll reload them.
  • documentation The bundling framework follows several common conventions such as: Selecting ".min" file for release when "FileX.min.js" and "FileX.js" exist. Selecting the non ".min" version for debug. Ignoring "-vsdoc" files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.
  • See stackoverflow.com/a/14967754/682105 for an answer to how you can configure the ignore list.
  • This fixed the problem... really good answer... thanks also in my case of weirdness i had a main.js and a main.min.remove.js (it picked up the main.min.remove.js) technical debt of some other person I cleaned after that all was sweeeet
  • I find it ridiculous that Microsoft decided to ignore my carefully coded bundles and just goes with whatever "min" file is included in the same directory. If I wanted to use the "min" file, I would SPECIFY the "min" file. FFS.
  • What if we release in debug mode? Does that mean that bundling will be broken in production--always delivering the first bundle it created after IIS was restarted?
  • You can still use bundling with web.config debug="true" if you also set BundleTable.EnableOptimizations = true
  • Removing .min files solved the bundling problem for me as well. In my case it probably occurred after merging between branches.
  • So you did not found any solution. I'm experiencing same problem, changed background image in css file, debuging in dev station works good, after publiching, old background appears. no minified file was updated. :(
  • The problem is that this is a CDN type service, so it is hosting files for other web sites and it does not use the files themselves. So, the referencing sites can be anything, and not necessarily ASP.NET sites. I also came upon the fact that Bundling has something called CDN-support.
  • asp.net/mvc/tutorials/mvc-4/bundling-and-minification (see CDN section) Could it be possible that I Just host the files normally without bundling and minification, and then possibly reference from other ASP.NET sites to these files using the CDN format: bundles.UseCdn = true; //enable CDN support string cdnPath = "mycdn.com/scripts/plugin/myplugin-x.y.z.min.js"; bundles.Add(new ScriptBundle("~/bundles/jquery", cdnPath).Include("~/Scripts/myplugin-{version}.js"));
  • Yes, if that's a feasible option, then that is most likely the best option, just have the ASP.NET sites use your CDN which hosts the bundle.