ASP.NET binding - a package that does not update after the file with the addition is included (returns 304 not changed)

I am trying to associate ASP.NET with an ASP.NET MVC 4 application. The situation is that I want to create a CDN style service that has JS and CSS files that you can access from other sites with this address: http: / /www.mycdn.com/scripts/plugin/js , which links and minimizes all included .js files.

The configuration of my package for a single file is as follows:

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

However, when I do this, packages are not updated, even after I change the source js files. I keep getting 304 Not Modified when I update my browser and the contents of the mini file are not updated. How can I update packages because it is useless to have packages with old content? I tried my best, but could not find a solution.

Thanks in advance!

+58
bundle asp.net-optimization bundling-and-minification
Aug 28 '12 at 12:10
source share
13 answers

I had exactly the same problem. I have a folder with two CSS files:

  • ~ / Content / main.css
  • ~ / Content / main.min.css (previously existing from my previous manual minimization process)

My binding code:

 bundles.Add(new StyleBundle("~/css/main").Include("~/content/main.css")); 

No matter how much I changed my main.css , the output was the same url with the same content:

 <link href="/css/main?v=6Xf_QaUMSlzHbXralZP7Msq1EiLTd7g1vId6Vcy8NJM1" rel="stylesheet"/> 

The only way to update the package is to recreate my solution - obviously not the best approach.

However , as soon as I deleted main.min.css , everything started working fine. Playing a little more, I found that if there is both main.css and main.min.css , then updating main.min.css will actually update the package ... Strange, but at least predictable.

+63
Nov 07
source share

After the fight, in order to find out what the package cache update does, I came to a few conclusions that I hope will help others:

If .min files are included in the package:

  • release mode + change min js code = cache update
  • release mode + change not min js code = cache update
  • debug mode + change min js code = cache update
  • debug mode + change not min js code = cache update

If .min files are NOT included as part of the package:

  • debug mode + change js code = cache update
  • release mode + change js code = cache update

Notes

  • In debug mode, I mean compiling web.config debug = true (and BundleTable.EnableOptimizations = false or omitted)
  • In release mode, I mean compiling web.config debug = false (and BundleTable.EnableOptimizations = true or omitted
  • Make sure you really make changes to the code. Changes such as spaces and comments do not affect the resulting mini-js, so the server is correct that there are no changes (so the bundle cache has not been updated).
+23
Dec 11 '15 at 21:27
source share

Ok, here is my story. I turned off min file generation for fewer files in Web Essentials. Old mine files were not deleted, and in the bundle they saw instead of updated CSS. Good luck

EDIT

After some time, I spent two more good 2 hours on the same problem. This time it was my mistake, I think I forgot the leading tilde, that is, I wrote

 Scripts.Render("/js/script") 

instead

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

For some reason, he sometimes worked, and sometimes he didn’t.

+6
Jun 27 '13 at 12:18
source share

I decided not to use System.Web.Optimization for this task, but found Microsoft Ajax Minifier, which is also included in the WebGrease.dll file that comes with the MVC4 library System.Web.Optimization. I wrote the following function, which I then called in Application_Start for each thumbnail 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 minimizes all files on Application_Start.

+3
Aug 29 '12 at 7:57
source share

Please note: if you use Google Chrome, caching is pretty aggressive. To ensure no caching, you can do Ctrl-Shift-I to open the developer panel. Go to Network and click Disable Cache . Make sure you keep it open. Refresh the page. Your cache should be cleared and file changes should be displayed.

Disable cache in Google Chrome

+2
Jan 04 '17 at 20:26
source share

I am not sure if the function that is currently installed will really support CDN, as it implicitly relies on url to contain hash code to prevent browser caching.

But I can try to help you try to get there, and maybe this is possible today ... One of the problems that could potentially be an obstacle is that the BundleHandler will return 304 to any packet requests containing the IfLastModified header, as it is assumed that The browser cache is always valid due to the fingerprint in the URL.

Can you add some details about how you display package links? Are you using something like Scripts.Render ("~ / Scripts / plugin / pluginjs")?

Your script package tag should look something like this:

 Good: <script src="/fbt/bundles/js?v=wvLq7H7qEZB2giyIRn7aEZAxhHOb2RfTYYh2HMd9EqM1"></script> 

If script tags reference an unhandled package without a version line, this will probably explain the caching issues you see:

 Not good: <script src="/fbt/bundles/js></script> 
+1
Aug 28 '12 at 20:22
source share

The binding operation is case sensitive. Make sure the file name has the correct case.

I had to change the line in my BundleConfig.cs:

 bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.css", "~/Content/Site.css")); <-- Uppercased. 
+1
Feb 06 '17 at 20:34 on
source share

I know it has been a while since it was updated, but I found that I just need to wait a couple of seconds for the bundle to catch up with my css changes. I have fewer bootstrap boot files in css and min.css, and it is definitely not instant to see my changes. For me, it was about 10 seconds on a fast PC with ssd. Your miles may vary depending on your system specifications.

0
Feb 27 '13 at 16:19
source share

I saw this answer, but none of this was for me. There were certain CSS rules that did reset the stylesheet, and I got the same hash even if I made changes to the CSS file. All this worked correctly for me.

In my case, a CSS selector rule violation was -

 #globalSearch.searching { ... } 

If I did it just

 .searching { ... } 

Everything starts working again, and any changes that I make in my css file correctly changes the hash node. Just add this answer as it may help someone.

0
Apr 16 '14 at 17:23
source share

Just update System.Web.Optimization from NuGet enter image description here

enter image description here

0
Jan 04 '15 at 23:54
source share

For what it's worth, I had the same problem only now, when one js file inexplicably refused to update no matter what (rebuild, force clear cache, etc.). After some time, I turned on client debugging tools in IE (F12) to start viewing network traffic, and this act itself caused the JS file to be updated. Go figure, but it worked.

0
Dec 08 '16 at 11:36
source share

Fiddler had a problem for me. After I closed dit and rebuilt my solution, I uploaded the changes to the js file for me.

0
Dec 29 '16 at 21:28
source share

I had a similar problem. In my situation, I had a CSS file referenced in a stylesheet and had this package mentioned in my MVC view. I also had the "EnableOptimizations" flag set to false in the package code.

Despite all this, the view refused to update to include the new CSS file.

My solution was to create a mini version of the CSS file and include it in the project, and it started working. I have no idea why this would be so, because this miniature file is not mentioned anywhere (even after the view has been updated), and it should not even be considered, since the code is not optimized. This is most likely a bug (or function) of the binding functionality. I hope this helps someone else run into this problem.

0
Jul 13 '17 at 16:25
source share



All Articles