To improve performance of site I updated my javascript references to use defer, such as:
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous" defer></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.16.0/jquery.validate.min.js" defer></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js" defer></script>
<script src="js/plugins.js" defer></script>
<script src="js/main.js" defer></script>
This did improve page load performance. Unfortunately a side-effect is that jquery function that handled the form post no longer was done using AJAX, it tried to reload the whole page which resulted in just the returned content appearing on a freshed page, opposed to just updating a DIV.
Code:
<script>
$(function () {
$('form').submit(function () {
if ($(this).valid()) {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
$('#result').html(result);
document.getElementById('contactForm').style.display = "none";
}
});
}
return false;
});
});
</script>
How do I update this jquery code to work correctly when the scripts are deferred?