Removing JavaScript from the document.

D

Daz

Hi everyone.

I would like to know if it's possible to clean up my scripts, or if you
will, 'make them biodegradable'. Some of my smaller script will be
download to the users browser, but I would like to clear them once I am
done, so as not to bog down the browser more than needed. I have tried
removing the script element, and/or setting the src attribute to null
and '', but the script itself still remains.

Here is some example code.

<head>
<script id="remove_me" type="text/javascript">
function foo(){
alert("bar!");
}
</script>
<script type="text/javascript">
function removeScript(){
script = document.getElementById('remove_me');
script.src = "";
script.parentNode.removeChild(script);
delete script;
}
</script>
</head>
<body onload="removeScript();"><body>
</html>

Note that there is no colsure created in this script, so the script
should be removed. But when I call upon foo() from the JavaScript
console in Firefox, it's still there!

Would anyone know how I can remove the entire script from RAM?

Many thanks.

Daz.
 
A

ASM

Daz a écrit :
Hi everyone.

I would like to know if it's possible to clean up my scripts, or if you
will, 'make them biodegradable'. Some of my smaller script will be
download to the users browser, but I would like to clear them once I am
done, so as not to bog down the browser more than needed. I have tried
removing the script element, and/or setting the src attribute to null
and '', but the script itself still remains.

to delete, remove the scripts or to try to pass its src to 'none' or to
empty, is of no interest because when you call that it is too late : the
scripts have been downloaded

Or you have a post-loader for your scripts

Or you re-define all loaded variables and functions to ''
 
D

Daz

ASM said:
Daz a écrit :

to delete, remove the scripts or to try to pass its src to 'none' or to
empty, is of no interest because when you call that it is too late : the
scripts have been downloaded

Or you have a post-loader for your scripts

Or you re-define all loaded variables and functions to ''

Thanks for that. Deleteing the var that contains the data makes
complete sense. I don't know why I didn't think of it. Doh! Perhaps
it's been a long day... :)

Daz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top