1

I am using bundles in my application and it works fine but problem came when I change any of my js file, it's changes not reflect I need to clear my cache. Below is my Bundle Class.

public class BundleConfig
{

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.IgnoreList.Clear();
        bundles.Add(new ScriptBundle("~/bundles/js")


            .Include("~/Scripts/js/jquery-2.1.1.js")
            .Include("~/Scripts/js/bootstrap.js")
            .Include("~/Scripts/js/jquery-ui.js")
            .Include("~/Scripts/js/jquery.dataTables.js")
            .Include("~/Scripts/js/amplify.core.js")
            .Include("~/Scripts/js/amplify.store.js")
            .Include("~/Scripts/js/bootstrap-datepicker.js")
            .Include("~/Scripts/js/bootstrapValidator.js")
            .Include("~/Scripts/js/jasny-bootstrap.js")

            .Include("~/Scripts/ApplicationCommand/AppCommands.js")
            .Include("~/Scripts/ApplicationCommand/ControlName.js")
            .Include("~/Scripts/ApplicationCommand/MDVisionServices.js")
            .Include("~/Scripts/ApplicationCommand/store.js")
            .Include("~/Scripts/ApplicationCommand/utility.js")

            .Include("~/Controls/Admin/Admin_SubMain.js")
            .Include("~/Controls/Admin/RefProvider.js")
            .Include("~/Controls/DashBoard/DashBoard.js")
            .Include("~/Controls/patient/Patient_Search.js")
            .Include("~/Controls/Scheduling/Scheduling_Calendar.js")
            .Include("~/Controls/Scheduling/Scheduling_Provider_Schedule.js")
            .Include("~/Controls/Scheduling/Scheduling_Search.js")
            .Include("~/Controls/Scheduling/Scheduling_WaitList.js")
            .Include("~/Controls/Search/Search_Admin.js")
            .Include("~/Scripts/MDVisionDefault.js")
            .Include("~/Scripts/js/jquery.toastmessage.js")
            .Include("~/Scripts/js/jquery.autocomplete.js")

           .IncludeDirectory("~/Scripts/ApplicationCommand", "*.js", searchSubdirectories: true)
           .IncludeDirectory("~/Controls", "*.js", searchSubdirectories: true)


           //.IncludeDirectory("~/assets/vendor", "*.js", searchSubdirectories: true)

          );


        bundles.Add(new StyleBundle("~/bundles/css")


.Include("~/Content/Blue/bootstrap.css")
.Include("~/Content/Blue/bootstrapValidator.css")


  );

}

Below is my aspx page where I register my bundle.

 <asp:PlaceHolder ID="PlaceHolder2" runat="server">
    <%: Scripts.Render("~/bundles/js") %>
    <%: Styles.Render("~/bundles/css") %>
</asp:PlaceHolder>

Now the problem is when I change any of my js file I need to clear cache too. Any one can give solution.

EDIT:

I have heard about Cache Busting but can't figure it out if that is helpful in my case please explain me how can I use in my case. Thanks

Sherry
  • 269
  • 2
  • 5
  • 18
  • Please see this SO post, http://stackoverflow.com/questions/9406003/how-do-i-turn-off-caching-for-my-entire-asp-net-mvc-3-website – Venkatesh Dec 09 '14 at 14:23
  • @Venkat Nope that not work for JS I tried before this but not working for me. – Sherry Dec 09 '14 at 14:33

1 Answers1

0

After Spending Some time I sort it out the issue and solved it.

On HTML page you need to render according to below technique on aspx page under head tag.

<script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/AppCommands") %>></script>
    <script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/AppSecurity") %>></script>
    <script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/ControlName") %>></script>
    <script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/MDVisionServices") %>></script>
    <script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/store") %>></script>
    <script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/utility") %>></script>
    <script src=<%: System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/Adminjs") %>></script>

Bundles.ResolveBundleUrl() will place the js or css for an year and if some change uploaded it will automatically update the reference.

Sherry
  • 269
  • 2
  • 5
  • 18