Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery disable cache buster for external scripts downloaded after calling the jquery load function

When loading html content through $.load, and the html content contains <script> tags referencing javascript files, the linked Javascript files are appended with a cache busting parameter, which prevents the file from being cached by the browser.

So, instead of requesting some­thing like <script src="/js/foo.js">, it requests <script src="/js/foo.js?_=123123">, caus­ing the script to be loaded every time.

Is there a way to disable this behavior?

like image 241
user648931 Avatar asked Sep 18 '25 08:09

user648931


1 Answers

You can try to force caching

$.ajax({
    url: "/yourpage",
    cache: true,
    dataType: "html",
    success: function(data) {
        $("#content").html(data);
    }
});

.

$.ajaxSetup({
cache: true // Enable cache as jQuery won't let the script be cached by default
});
like image 184
intika Avatar answered Sep 19 '25 21:09

intika