I can't seem to get the javascript files to update in VS2013, asp.net using bundles. The image is after I have done a clean/rebuild, bundle clear and resetall, and deleted the browser history in IE (including cookies, website data, temp files and website files.) I have wasted day after day trying to get my site working. I have googled this a hundred times and found no satisfactory answers. What am I missing? There has got to be an easy way to do this.
As I said in the comment, don't use bundles during development of javascript or CSS files at all.
Just comment out the part where the bundle is rendered and include the corresponding files the classic way like this:
<script src="~/Scripts/myscript.js?v=#DateTime.Now.Ticks" type="text/javascript"></script>
When deploying the project remove that line and reactivate the previously commented bundle-rendering call.
Because the uri-parameter version string of the "classic-approach" is changing on each request you can be sure that you always have the latest version of javascript file and are not dependent on some CacheDependency of the Bundle-Framework to trigger or update (which apparently is not working all of the time).
Just don't forget to remove that manual script include so that your users' browsers can actually cache the resources.
Related
On the website I'm building we are using the built in bundling and minification.
We render our scripts by using the #Scripts.Render
#Scripts.Render("~/bundles/scripts")
it generates a link like:
bundles/scripts?v=3-DUUAAegZl4yp1O4V0VL0GnJ0U6gT3De8yKb41lfGs1
Here I thought that the hash:
v=3-DUUAAegZl4yp1O4V0VL0GnJ0U6gT3De8yKb41lfGs1
would be smart and change if we made changes to the inlcuded scripts but it seems like that is not the case.
Now when we are trying to implement a custom cdn for out bundling it fails on updates since the hash never seems to change.
Does anyone know of a solution to change the hash when the script changes or if we are doing something wring?
Edit:
I noticed that there is a difference in behavior depending on what environment I'm using.
Local development it seems to be working but it doesn't work on the staging server.
Should there be a difference?
Edit2:
Seems to be working as it should on production servers as well. Will have to do more research on what the cause can be.
Edit3:
Seem that the one causing the problem was in the registry LogRewrittenUrlEnabled was set to false to allow url rewrites at the same time as using dynamic content compression (gzip) so will have to find another way to enable this
You're right, the cache-buster hash should change if you change the contents of a script. There's some useful information about how the cache for bundling works that may help you here ASP.NET MVC Bundling cache. (Detecting css files changes) (internal behaviour).
The problem was that on the server we had in the registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v LogRewrittenUrlEnabled set to false
And if you have that then the cache-buster hash is not refreshing when the content i bundle is changed.
This question already has answers here:
force browsers to get latest js and css files in asp.net application
(23 answers)
Closed 8 years ago.
I'm maintaining an asp.net 3.5 website deployed on IIS 6.0 and I have made some fixes to a javascript file "scormapi.js" and should copy it (just this file) to the client website server. My problem is that the script reference to to this file with its version is injected into the page through server side code:
ClientScript.RegisterClientScriptInclude("DWScormAPI.js", ResolveUrl("~/Scripts/scormapi.js?Version=3.3"))
Which means that the client browser will use the cached file if I just do a copy of the file. Is there anyway to force the browser to use the new copied version of the file without recompiling and deploying the dll.
Thanks
EDIT:
I thought of adding to the aspx pages that uses the js file a tag that reference this js file with a different version number, or maybe using jquery $.getScript(). But in this case I would have two script references to the same file on the same page and I wonder if there is anyway to tell the page use this version of the file instead of that version.
NB: This is not duplicate question. I'm asking whether there is an alternative solution that avoids me modifying my server side code and then do a recompile and full deployment. The duplicate question some folks are referring to is just not what I'm asking about.
The only way to 'force' a browser to fetch a file instead of used its cached version is to change the URL in some way. In our system, our 'url injection' includes a query string with a timestamp - looks like "...something.js/140324" for a file that changed yesterday.
Here are some ideas for updating the js file for your users.
You could have the ?Version= have a value that changes every X minutes which forces the client to load a fresh js file every X minutes when visiting the website.
If you really must detect it server-side you could let the ?Version= have the value matching the last edit info for that file. E.g. let the server find the file on the system and examine last edit info and append that info to the ?Version= url part.
I have a MVC + C# based application, which contains a lot of js files, images and css, basically static content. Its running on production as well. There was an issue reported by customer to which we provided an immediate solution by clearing cache on his machine. As per me, this should not be the ideal solution.
We have provided caching in our web.config file as given below:
<staticContent>
<clientCache cacheControlMaxAge="365.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>
It is for one year, so how do i tackle this situation, as in if there is a new deployment to production, which has changes in static content, how do I make sure, the cache will be refreshed. Our prod deploy happens generally each 2 months.
And what are generally best practices for taking care of these cache things?
We also face this problem, when we do development, change static content, then our QA tests these, they dont find the changes, and we realize we have to clear cache.
Use Bundling it for js and Css. Bundling takes care of caching.
It appends the url for a Bundle with some charactor.
If any changes comes in js or Css file it updates the appended url hence browser takes these file as new file and reloads it.
You can use Bundling with MVC3 and superior versions.
refer this link
I have looked for answers to this question, but I am not sure if I am asking it right.
I am looking for what do developers do in this situation:
I am developing an ASP.NET C# applications. I have CSS and SCRIPT files, and I am using jQuery. I install my application to the Web Servers (or I have my customer install them). If I have made any changes to my script files by adding some new jQuery or something, my customers don't get that effect after I do an update. I assume that the reason is that their browsers cache the file on the local computer and they do now download the new file from the server.
In my development environment I clear the cache when I close the browser and on IE I tell it in options to always load from the server. That way when developing I never have cached data.
What is the best practice to make sure that if I do make changes, those files get refreshed on the client computers after I do an update? Is there something in Code I can do?
I really don't want to change the filename and update all my script references.
Thanks,
Cory
The traditional way is to append a query string argument to the end of the reference to the css/script file path. For example, if you append a build number as the query string, each version of the software will make its own request for the relevant resource.
I have added a custom button, with url + javascript by chaning the isv xml file, as described on
http://msdn.microsoft.com/en-us/library/cc150860.aspx
and all works fine. However, when I try and replace the file in the /ISV/ folder, it behaves the same as the original copy, I assume this is caching related. However, if I access the file from outside the CRM that is http://server/ISV/file.htm it has the latest and correct version. How do I get around this caching issue.
Thanks
So your ISV Option points to "/ISV/file.htm"? I think in the past I've noticed CRM's IIS site caching static files for 3 days. What I would do is when you replace your file.htm in your ISV folder, also update the ISV.config:
So change it to point to "/ISV/file.htm?vers=00001" and then increment each time you update the file.