How to make sure to have fresh copy of files after each release of application (my website ) to the end user - asp.net-mvc

I am having really some strange issue for js,images & css files related to caching.
I am using IIS 8.5 & asp.net MVC for my application, to overcome cache issue after each production release i have added version in web config and i use it mention below way. (for some common files i m using bundling)
web.config
<add key="Config.Version" value="1.0.0.0.65" />
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
some.cshtml
<script src="#Url.Content("~/Scripts/somefolder/some.js?v=" + Config.Version)" type="text/javascript"></script>
I have also enabled dynamic compression in IIS.
I wants to make sure after each Release /Publish of the application, The end user /client side update files should be loaded instated of older one.
(Here issue is that even though sever has latest updated files some time client needs to hard refresh(ctrl + F5) or similar techniques ).
My main question how can i make sure each time everyone gets the latest file version.
Note: I also don't want to compromise with cache to get performance.
Can anyone show me best practice or general guideline for this ?

Adding a query string param is enough to invalidate all client-side caching. Based on the HTTP spec, the query string is part of the URL and any change makes it a completely different URL. A browser that didn't reload the CSS/scripts would be broken. I know of no major browser that wouldn't reload, though.
One thing to consider, however, is that the HTML page itself may be getting cached. If the client is just loading the old HTML, then the old reference to the CSS/scripts is the same and are also loaded from cache. Make sure you're not allowing HTML documents to be cached if you want to ensure that the user always gets the latest version.

Related

Azure Changes not getting published

I have made changes to my css on my MVC5 project that are working as intended on my local version but when I deploy to Azure the changes are not working.
I have tried creating a min.css file but this did not work
Have you done a hard refresh and pulled a copy of the stylesheet from the server to see if the changes you made are actually there? Http caching could be the culprit depending on how you're packaging your CSS.
Next, check the page source to make sure that your page is actually requesting the stylesheet you think it is. For example, if your site is requesting styles.min.css but you only made changes to styles.css and didn't create a new minified version, that'll cause problems.
Third, I'd check the elements that do not have the styles you're expecting and trace the styles with something like Chrome Developer Tools to ensure that your styles aren't being overridden in a way you're not expecting.

mvc asp.net web project first load

I published My Web project that written by C# MVC5 ASP.NET and Entity framework on a Shared Host. First Time that it loads, speed is very slow and take a long time almost 12 second but after that it is ok . I tested my website on a gtmetrix.com and fortunately is in A class.Could anyone tell me why it takes a long time for first load ?I have some suggestion.
1)it because of entity framework ?
2)it because of a lot of library that I used them and it needs to load these dll files before load ?
3)I need some config in IIs (I dont access to IIs Server because Im using shared host)?
(also compilation debug is false)
I am appreciated If some one help me .
web site address is www.kajalmarket.com and is uploaded most recently .
You can precompile prior to deployment if you're concerned.
Here's more info:
https://msdn.microsoft.com/en-us/library/ms227972(v=vs.90).aspx
Precompiling an ASP.NET Web site provides faster initial response time for users since pages do not have to be compiled the first time they are requested. This is particularly useful for large Web sites that are updated frequently.
You can also select "Precompile during publishing" if you publish via Visual Studio:
Click here to see screenshot.
Another option is as follows taken from ( https://msdn.microsoft.com/en-us/library/ms366723.aspx ):
If you want to be able to change top-level files without causing the whole site to be recompiled, you can set the optimizeCompilations attribute of the compilation element in the Web.config file to true. If optimizeCompilations is true, when you change a top-level file only the affected files are recompiled. This saves time but can cause run-time errors depending on the type of changes you make to a top-level file.
With this method you should see a reduced re-compilation time as it only recompiles those top level files that have changed.
HTH

Redirecting legacy URLs in DotNetNuke

We are building a revamped version of our old site in DotNetNuke. There are many pages that link to pages on our old site and we would like those old URLs to still lead to relevant information on the new site. The old URLs end in a variety of extensions, and sometimes in no extension (our old site is a mishmash of several platforms as well as static files). Does a DNN plugin exist that allows for such redirects? Friendly URLs aren't entirely adequate.
note: I realize that this could be handled in IIS, but we would like our non-coder, non-admin site manager to be able to handle this dynamically.
You will probably want to use a Module like this
http://www.dnnsoftware.com/forge/open-url-rewriter-for-dnn-dotnetnuke/view/extensiondetail/project/openurlrewriter
There is another option though. You can actually put URL records into the database directly, I believe you would simply add a record to the TabUrls table, the TABID is the page in DNN you want to point to. Then you put in the URL, and the HTTPStatus of 301.
You could do that for all the old pages if you know where they need to be mapped to in DNN.
You have to force all request through the ASP.NET pipeline, and you can do that by adding only this single line to the web.config of your application:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

ASP .Net MVC - Images not being shown in published build

I am developing an ASP .Net MVC application and on my dev machine, the application runs as expected and, more importantly, the images mentioned in the CSS file are displaying correctly too.
However, when I publish this application to a testing server, the web app runs fine, but the images are not shown.
If I modify the URL in IE when testing the output from the test server, the image is returned, meaning that the file is there but it just won't appear within the view page when using the site normally.
I have tried alternative servers too, but the result is the same.
To confirm, here's a line from the CSS page referencing the image...
background-image: url('/Content/Images/Logo/myLogo.jpg');
Any suggestions?
Cheers
Brett
The URLs are not correct, likely due to the fact that you are publishing in a subfolder and so they are no longer at the root of the server. I usually use Url.Content( "~/Content/Images/..." ) to build the url instead of hard-coding it. That way it will take into account the routes when building the path.
Example:
<img src='<%= Url.Content( "~/Content/Images/banner.jpg" ) %>' alt="Banner" />
I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.
When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.
That fixed it for me, hope it works for you.
Possible relative paths are wrong...Possible that they are wrong for CSS file itself. You can use FireBug to see if CSS loaded correctly, then you can examine image request, often in such situations you will see red(error) items. This could help to localize problem.

Rails and javascript cache

I'll start to develop a new app that uses a lot of heavy js librarys (prototype, scriptaculous, tinymce and so on).
Someone told me to make all the app using ajax, so all the js files will be loaded only once.
My question is, I really must do everything on ajax?
Lets say if I call myapp.com/projects and projects use all those js files, then I click on a "show" link and I'm redirected to myapp.com/projects/1 on this redirect, all js will be reloaded again?
No, your Javascript files will not be loaded again, they will be cached on the client.
But yes, your application will need to check with the server at every page load, the server often responding that the scripts have not changed. By using AJAX, you reduce the number of connections to the server. You can reduce the number of connections by concating all you Javascript files into one.
Note however that AJAX will add some new problems, like forcing you to track memory leaks as your application will never unload its objects if you never reload a new page.
If you are not at ease with Javascript, I strongly suggest sticking with the "old" model of reloading the page everytime. If you have performance issues, you can deal with them later.
Reloading Images, Scripts, etc...
Short answer: yes
Long answer: depends
When you view a page, your browser will request the HTML, once it has the HTML it will start to load external references (images, scripts, etc...). When it goes to request an image or a script, your browser may send a header which says when it got it last and stored it in its cache. The web server may respond with a 304 Not Modified code which tells the browser to use the cached version saving it from downloading it again.
Even if the browser doesn't use these headers, it will still be caching, it just won't know when the cache should expire. When you use the rails helpers to include images and scripts, it will append a number onto the end of the url which is unique to scripts contents. So if you change the contents, a new url will be used forcing the browser to get the updated version.
Use Google's Ajax Libraries API! Google now hosts the most popular js libraries including Prototype, Scriptaculous and jQuery. Once they host a specific version they are committed to hosting that version indefinitely.
There is a small Rails plugin by Ryan Heath at github:
script/plugin install git://github.com/rpheath/google_ajax_libraries_api.git
Then in your views instead of using the default
<%= javascript_include_tag :defaults =>
use this instead:
<%= google_jquery =>
<%= google_prototype =>
<%= google_scriptaculous =>
You can specify versions if you want. Check out Ryan's readme at github for more information.
This way you don't have to bother setting up an asset host (at least not for your standard javascript) and save yourself a truckload of bandwidth!

Resources