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.
Related
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.
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 just started an asp.net c# project and I was trying to change the text-align of the .title and background color of the .header. I add the required code to the style sheet, but nothing changes in the header of the form. I'm probably missing something simple here, can someone point me in the right direction?
Stylesheets are usually cached by the browser to speed up browsing.
You can either force-refresh (SHIFT+F5) or append a value to the stylesheet path to cache-bust it.
style.css?v1
By changing v1 whenever you want a change to be forced out to all browsers, it will replace the cached version as resources are cached per URI.
Just try stopping your Local development server and do clean and build solution before running the application.
Even clear your temporary internet folder which may contain stale copy of your css file.
Right clicking in the markup view , you should see an options that says view in browser. This should reload anything cached.
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.