I\'m aware of dynamic script/css loading by adding or
tags to head or body of the page, but then it will be executed by
Just found out one more option to load script/css asynchronously (without conflicting to SOP) - is to use <object>
tag:
<object data="http://podlipensky.com/examples/dynamicscript/hey.js" />
Found this approach here. So I'm just sharing with you my findings, hope it will be useful.
You can also use an iframe
and use the script/css URL as the src
of the frame (so it isn't evaluated/applied at all), although you'd want to be sure in that case that the JavaScript/CSS was delivered with Content-Type text/plain
to avoid unfortunate things happening with <
characters and such. Although you should run into SOP issues with this approach as well, on a decent browser, if the iframe
src
is from a different origin.
Other than that, I think you largely have it covered with the options you list.
If your script simplty defines a function then it can be executed without actually running anything. Of course, this would require collaboration from both sides ala JSONP
//jsonp
var result = {/*...*/};
//missingnonp
var f = function(){ /**/ };
Assuming you control the server that delivers the page, into which you want to load the JS in question, the easiest way is to submit the URL via AJAX to your server, load it from there (e.g. via PHP file_get_contents($url);) and get it back as a result of the AJAX call.