C# ASP.NET MVC Forms Adding Form Validation Improving Validation CSS Styles

Does scripts order matter?

For example I have this in this order(like the video):

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.validate.bootstrap.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/bootstrap-datepicker.min.js"></script>

validation works well. But when I just switch the third script with the first, validation does not work well.

1 Answer

Steven Parker
Steven Parker
201,932 Points

Whether the order matters will depend on what's in the script. If the script uses anything that is contained in a different script, the other script(s) must be loaded first.

For third-party code, the supplier's instructions should mention the necessary loading order. Package naming may also be a clue. In your example above, if you know that Bootstrap depends on jQuery, the order shown is intuitively the appropriate order with the possible exception of the the third and fourth items (which may be interchangeable, I didn't check the specs).

Thanks <3