Removing JavaScript from the document.

Discussion in 'Javascript' started by Daz, Jan 14, 2007.

  1. Daz

    Daz Guest

    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.
    Daz, Jan 14, 2007
    #1
    1. Advertising

  2. Daz

    ASM Guest

    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 ''


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Jan 14, 2007
    #2
    1. Advertising

  3. Daz

    Daz Guest

    ASM wrote:

    > 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 ''
    >
    >
    > --
    > Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    > Stephane Moriaux and his (less) old Mac already out of date


    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.
    Daz, Jan 14, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GhislainTanguay
    Replies:
    3
    Views:
    6,307
    Joe Reazor
    May 21, 2004
  2. Matt
    Replies:
    6
    Views:
    753
    Alex Shirshov
    Apr 13, 2004
  3. Chris  Chiasson
    Replies:
    6
    Views:
    614
    Richard Tobin
    Nov 14, 2006
  4. Chris Gallagher

    Removing a tag from an xml document

    Chris Gallagher, Nov 24, 2006, in forum: Ruby
    Replies:
    2
    Views:
    130
    Chris Gallagher
    Nov 24, 2006
  5. Hvid Hat
    Replies:
    3
    Views:
    122
    Thomas 'PointedEars' Lahn
    Jan 24, 2008
Loading...

Share This Page