javascript - How can I set the http RequestHeader for a file load in the $script.js library? -


the $script.js library using

https://github.com/ded/script.js/

has following javascript. need set request header in code block not sure how this:

var el = doc.createelement("script"), loaded = false; el.onload = el.onreadystatechange = function () {   if ((el.readystate && el.readystate !== "complete" && el.readystate !== "loaded") || loaded) {     return false;   }   el.onload = el.onreadystatechange = null;   loaded = true;   // done! }; el.async = true; el.src = path; document.getelementsbytagname('head')[0].insertbefore(el, head.firstchild); 

here's example of similar (not part of $script.js) set request header:

var xmlhttp = new xmlhttprequest(); xmlhttp.open("get", "/scripts/pages/home.js", false); xmlhttp.setrequestheader("x-custom-header", "my values"); xmlhttp.send(); var m = document.createelement('script'); m.appendchild(document.createtextnode(xmlhttp.responsetext)); document.getelementsbytagname('head')[0].appendchild(m); 

the first code block (the 1 need use can modify slightly) not clear me. know how can change first code blocks (used in $script.js) set request header?

if i'm interpreting library correctly, xmlhttprequest isn't used directly $script.js. appears creating <script></script> tags dynamically , letting browser handle downloading script files. using library, not appear can specify custom headers.

altering request headers browser sends via javascript not possible according of articles i've read including answer question on so: is possible alter http request's header using javascript?

if want set custom headers, you'll need use dynamic loading library uses xhr load scripts. here article i've found patterns type of functionality: on-demand javascript.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -