1

I'm working on a asp.net web-form website in which I use ../ for routing files like js files, styles, etc. When I decided to apply ScriptBundle and replace ~/ instead ../ the website didn't work at.
js file completely are loaded on browser but they didn't work.

This is my code before ScriptBundle that work perfectly:

<!-- Page Scripts Starts -->
<script src="../Script/jquery.min.js"></script>
<script src="../Script/jquery.colorpanel.js"></script>
<script src="../Script/bootstrap.min.js"></script>
<script src="../Script/jquery.flexslider.js"></script>
<script src="../Script/bootstrap-datepicker.js"></script>
<script src="../Script/owl.carousel.min.js"></script>
<script src="../Script/custom-navigation.js"></script>
<script src="../Script/custom-flex.js"></script>
<script src="../Script/custom-owl.js"></script>
<script src="../Script/custom-date-picker.js"></script>
<!-- Page Scripts Ends -->

and this is after ScriptBundle:

<!-- Page Scripts Starts -->
        <%: Scripts.Render("~/Script/js") %>
<!-- Page Scripts Ends -->

Cs file:

    bundles.Add(new ScriptBundle("~/Script/js").Include(
              "~/Script/bootstrap-datepicker.js",
              "~/Script/bootstrap.min.js",
              "~/Script/custom-date-picker.js",
              "~/Script/custom-flex.js",
              "~/Script/custom-navigation.js",
              "~/Script/custom-owl.js",
              "~/Script/jquery.colorpanel.js",
              "~/Script/jquery.flexslider.js",
              "~/Script/jquery.min.js",
              "~/Script/owl.carousel.min.js"));
Sasan
  • 644
  • 9
  • 29
  • https://blogs.msdn.microsoft.com/rickandy/2012/08/14/adding-bundling-and-minification-to-web-forms/ – ArunPratap Oct 10 '18 at 05:18
  • That is beacuse the order of the script files (in .cs) is wrong. `jquery.min.js` should most likely be first. Change the order so that it is the same as per your working example. Since atleast all `jquery.*.js` files uses `jquery.min.js` they must be loaded after `jquery.min.js`. – Sani Huttunen Oct 10 '18 at 05:18
  • didn't work doesn't give us any idea that what actually did not work. Kindly post what actually did not work. What was rendered in HTML when you used bundles? – Ankush Jain Oct 10 '18 at 05:20
  • `"~/Script/jquery.min.js"` must be on the first or topmost order. Other JS files should be ordered based from their dependency/importance. – Tetsuya Yamamoto Oct 10 '18 at 05:25
  • @Sani Singh Huttunen - Thank u so much it works. If you you want, put your post as a complete answer and I'll check it true. – Sasan Oct 10 '18 at 05:26

1 Answers1

2

That is beacuse the order of the script files (in .cs) is wrong. jquery.min.js should most likely be first. Change the order so that it is the same as per your working example. Since atleast all jquery.*.js files uses jquery.min.js they must be loaded after jquery.min.js.

Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79