In order to release the script resources, additional processing is usually required after the return.
Copy codeThe Code is as follows:
Script = document. createElement ('script ');
Script. src =
'Http: // example.com/cgi-bin/jsonp? Q = What + is + the + meaning + of + life % 3F ';
Script. id = 'jsonp ';
Script. type = 'text/javascript ';
Script. charset = 'utf-8 ';
// After the label is added to the head, it is automatically loaded and run.
Var head = document. getElementsByTagName ('head') [0];
Head. appendChild (script)
In fact, many popular JS libraries use this method to create a scrui tag, assign an ID to it, load the script (such as YUI get (), and clear the tag after loading and callback. The problem is that when you clear these script tags, the browser only removes the tag node.
Copy codeThe Code is as follows:
Var script = document. getElementById ('jsonp ');
Script. parentNode. removeChild (script );
When the browser removes the tag node, it does not recycle the JavaScript Resources in the node. This means that it is not enough to remove the tag node. You must manually clear the content of the script tag node:
Copy codeThe Code is as follows:
// Remove any old script tags.
Var script;
While (script = document. getElementById ('jsonp ')){
Script. parentNode. removeChild (script );
// The browser will not recycle the objects pointed to by these properties.
// Manually delete it to avoid Memory leakage.
For (var prop in script ){
Delete script [prop];
}
}