I have created style and script bundles in my MVC project as given below. Now I need to enable caching for bundles as well. Is there any way by which we can control caching duration for these bundles?
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/lib/bootstrap/css/bootstrap.min.css",
"~/lib/owlcarousel/owl.carousel.min.css",
"~/lib/owlcarousel/owl.theme.default.min.css",
"~/StylesCdn/google-font.css",
"~/assests/css/common.min.css"
));
bundles.Add(new StyleBundle("~/bundles/bottomcss").Include(
"~/lib/chartist/scss/chartist.min.css",
"~/lib/chartist/chartist-plugin-tooltip.min.css",
"~/StylesCdn/export.min.css"
));
bundles.Add(new ScriptBundle("~/bundles/js").Include(
"~/lib/bootstrap/js/jquery.min.js",
"~/assests/js/homelayout.min.js"
));
bundles.Add(new ScriptBundle("~/bundles/bottomjs").Include(
"~/lib/bootstrap/js/bootstrap.min.js",
"~/lib/owlcarousel/owl.carousel.min.js",
"~/assests/js/app.min.js",
"~/Content/Validation.min.js",
"~/assests/js/InvestmentCalculator.min.js",
"~/assests/js/common.min.js",
"~/assests/js/BindDate.min.js"
));
OK, so the other answers do not seem to be entirely correct. You can influence how browsers attempt to cache these files by altering the 'staticContent' element in your web.config. (Providing you are on IIS7 or later)
This affects what caching headers static content (e.g. images/scripts) will be served with. e.g. you can cause a max-age header and date to be served by setting the following:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
Further reading as to what can be set can be found in the documentation here:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/clientcache
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With