javascript - jQuery adding querystring to script load? -


adding js page:

$("#divexample").append("<script type='text\/javascript' src='\/scripts\/test_code.js'><\/script>"); 

causes request to:

http://.../scripts/test_code.js?_=1395691742415 

i need eliminate query string preventing js file being cached. best guess in way connected jquery ajax, appends same style of querystring when doing types of call (e.g. jsonp).

background on why i'm doing this: need push off script load (which part of larger js block) until after page ready event has completed. above cut down sample shows same symptoms.

currently using jquery 1.8.3 hope answer doesn't include upgrading since mess dependencies.

set jquery cache global true prevent this.

$.ajaxsetup({     cache: true }); 

even though appears config ajax, affects <script> tags you're using.

if don't want apply global ajax requests, can use plain javascript (no jquery) it:

var s = document.createelement('script'); s.type = 'text/javascript'; s.src = 'test.js'; document.getelementbyid("divexample").appendchild(s); 

the third option can use $.ajax import script so:

$.ajax({   url : 'test.js',   type : 'script',   cache : true,   success : function(){    } }); 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -