I am using the JSONP/dynamic-script-tag technique to perform cross-domain AJAX (There's no XML, but you know what I mean).
Initially, I wrote my own solution, but I could not come up with an elegant way to remove the script after it executed. My strategy was just to pass an ID and on the callback remove the associated script, but I realized this would prevent caching, which I do not want to do.
That went something like:
1) Dynamically insert: <script src="http://example.com/handler.php?callback=x&scriptid=y"></script>
.
2) The script loads and runs x(); removeScript(y);
where removeScript
took the appropriate script element out of the head element.
It worked great but ruined caching. So I was excited to learn jQuery provides a jsonp method and quickly implemented it, figuring they had got this all figured out. Instead jQuery leaves the script element there.
Is there a clean way to remove these elements?