JS, CSS bundles are not updated when included file is changed

Jacob
Jacob
Member
56 Points
13 Posts

Hi,

I am working on Optimization of MVC Project in which I am using css and js file to bundled to a single files. But when I updated in css or js it not reflecting in web browser. After Rebuild the project it worked fine.

What is wrong? 

Views: 12752
Total Answered: 2
Total Marked As Answer: 1
Posted On: 30-Oct-2015 00:42

Share:   fb twitter linkedin
Answers
Jacob
Jacob
Member
56 Points
13 Posts
         

Hi,

This is my bundle code:

using System.Web;
using System.Web.Optimization;
namespace shopnamespace
{
public class BundleConfig
{
// For more information on Bundling, visit https://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
 
bundles.Add(new ScriptBundle("~/bundle/js")
.Include("~/Scripts/jquery-1.8.2.min.js",
"~/Scripts/jquery-ui.js",
"~/Scripts/html5.js",
"~/Scripts/Product.js",
"~/Scripts/CommonValidation.js",
"~/Scripts/jquery.unobtrusive-ajax.min.js"));
bundles.Add(new ScriptBundle("~/bundle/footerjs")
.Include("~/Scripts/jquery.fancybox.js",
"~/Scripts/HeaderScrollTop.js"));
bundles.Add(new ScriptBundle("~/bundle/jsdetail")
.Include("~/Scripts/jquery.jcarousel.min.js",
"~/Scripts/jcarousel.responsive.js",
"~/Scripts/jquery.easing.1.3.js",
"~/FlexSlider/js/jquery.flexslider-min.js",
"~/FlexSlider/js/flexslider-tab.min.js",
"~/Scripts/scriptbreaker-multiple-accordion-1.js",
"~/Scripts/validation.js",
"~/Scripts/cloud-zoom.1.0.2.min.js",
"~/Scripts/popupwindow.js"));
bundles.Add(new ScriptBundle("~/bundle/jsraty")
.Include("~/Scripts/owl.carousel.js","~/StarRating/lib/jquery.raty.js"));
bundles.Add(new StyleBundle("~/bundle/css")
.Include("~/Content/style.css",
"~/Content/stylesheet.css",
"~/Content/jquery-ui.css",
"~/Content/easy-responsive-tabs.css",
"~/Content/navbar_techandall.css",
"~/Content/banner.css",
"~/Content/responsive.css",
"~/Content/normalize.css",
"~/Content/category.css",
"~/Content/jquery.fancybox.css",
"~/Content/fancybox.css",
"~/Content/feedbackform.css",
"~/Content/font-awesome/css/font-awesome.min.css"));
bundles.Add(new StyleBundle("~/bundle/cssdetail")
.Include("~/StarRating/lib/jquery.raty.css",
"~/Content/owl.carousel.css",
"~/Content/owl.theme.css"));
BundleTable.EnableOptimizations = true;
}
}
}

Global.asax: 

public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
//WebApiConfig.Register(GlobalConfiguration.Configuration);
GlobalConfiguration.Configure(WebApiConfig.Register);
//FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}

 

And in view page as:

<link href="<%=clsApplicationSetting.GetURL()+"/bundle/css"%>" rel="stylesheet" />
<script src="<%=clsApplicationSetting.GetURL()+"/bundle/js"%>"></script>

 

 

Posted On: 30-Oct-2015 03:42
Brian
Brian
Moderator
2232 Points
14 Posts
         

Hi Jacob,

Use render method to call script and css bundle as:

In ASPX engine:

<%:System.Web.Optimization.Styles.Render("~/bundle/css") %>
<%:System.Web.Optimization.Scripts.Render("~/bundle/js") %>

In Razor engine:

@System.Web.Optimization.Styles.Render("~/bundle/css")
@System.Web.Optimization.Scripts.Render("~/bundle/js")
Posted On: 30-Oct-2015 03:49
 Log In to Chat