I use getScript to load dynamically my plugin:
$.getScript('js/code.photoswipe.jquery-3.0.4.min.js', function () {
//do magic
});
-
How do I disable caching busting?
At the moment it generates numbers at the end: js/code.photoswipe.jquery-3.0.4.min.js?_=1326992601415
I saw this, but not sure how to use it in my case:$.getScript = function (url, callback, cache) { $.ajax({ type: "GET", url: url, success: callback, dataType: "script", cache: cache }); }; -
If I call $.getScript multiple times adding the same js file, does it do request each time to get that file? If so, is there a way to check if we already imported that script, so we could avoid calling getScript again for the same file?
Your browser will cache the url accordingly already.. So you don’t have to worry about caching.
If however you want to bust the cache simply add a random string to the url like so:
?' + Math.random()will allow for a random number to append to your js file so caching is broken with each request for the file (as it randomly generates a number)