4

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?

1 Answer 1

3

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 }); 
Sign up to request clarification or add additional context in comments.

1 Comment

ajaxSetup is global so I didn't want to use that. I might try your first suggestion though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.