Reputation: 378
I have been taught that it is good for page loading speed and user experience to defer loading JavaScript that is non-essential for above-the-fold content.
Example:
$(document).ready(function() {
var e = document.createElement("script");
e.src = "//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js";
var t = document.getElementsByTagName("script")[0];
t.parentNode.insertBefore(e, t)
});
But are external JavaScript files that are deferred like this still cached by the user's browser the same way as direct calls to external JavaScript hardcoded into the HTML?
Upvotes: 1
Views: 4189
Reputation: 17711
Yes, it will. Over sixty browsers - including Blackberry, Epiphany, and PlayStation - happily, and surprisingly, honor caching headers for scripts loaded dynamically.
(See here...).
Upvotes: 1
Reputation: 51
Yes it will cache it. So use timestamp or the updated version in the url via query string.
Please see this post for more details
When does browser automatically clear cache of external JavaScript file?
Upvotes: 0