RXGeorge
asked on
Browser Caching
We have a .NET MVC WebApi 2 web application which has a browser client using html/css/javascript. The html page will reference the css and .js files. We'd like to make sure that when we publish a new version of the site, the user gets it immediately. It seems that caching can prevent the user from seeing the latest content for a long period of time. I don't want to force the user to manually refresh it.
1. What are my options here? Is there HTML tags to control this?
2. Should I be concerned about version mismatches between HTML/CSS/JS caused by browser caching?
1. What are my options here? Is there HTML tags to control this?
2. Should I be concerned about version mismatches between HTML/CSS/JS caused by browser caching?
First, you have no direct control over caching in a user's browser. They can mess it up if they want to. However, the best way I have found to prevent caching from blocking changes in CSS and javascript files is to simply change the name. All you have to do is add a number or something to the newest version and save that in the main file. The browser will see that as a file it does not have in it's cache. Something 'main.css' then 'main1.css' and 'main2.css'.
I usually add a cache busting query: you could do main.css?v1.2 or something... that way you don't have to rename the file. If you want users to get a new copy of the file every time they open the page, you could put a timestamp code right where you are referencing the file. But that is probably not what you want.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The meta in the header is not very reliable. In the end the user controls caching and the browser may, or may not respect the meta directives.
While you can use most of the suggestions here successfully, a really radical approach is to maintain compatibility and let the user transition at their own pace, Unless there is a critical security or performance issue there should be no real urgency involved that requires extra effort to deploy changes. When there is something critical, then there are any number of ways to put up a notice to let users know that they need to apply a critical update.
Cd&
While you can use most of the suggestions here successfully, a really radical approach is to maintain compatibility and let the user transition at their own pace, Unless there is a critical security or performance issue there should be no real urgency involved that requires extra effort to deploy changes. When there is something critical, then there are any number of ways to put up a notice to let users know that they need to apply a critical update.
Cd&
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.