Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:13:41+00:00 2026-05-31T10:13:41+00:00

As the title says, if I remove a script tag from the DOM using:

  • 0

As the title says, if I remove a script tag from the DOM using:

$('#scriptid').remove();

Does the javascript itself remain in memory or is it cleaned?

Or… am I completely misunderstanding the way in which browsers treat javascript? Which is quite possible.

For those interested in my reason for asking see below:

I am moving some common javascript interactions from static script files into dynamically generated ones in PHP. Which are loaded on demand when a user requires them.

The reason for doing this is in order to move the logic serverside and and run a small script, returned from the server, clientside. Rather than have a large script which contains a huge amount of logic, clientside.

This is a similar approach to what facebook does…

Facebook talks frontend javascript

If we take a simple dialog for instance. Rather than generating the html in javascript, appending it to the dom, then using jqueryUI’s dialog widget to load it, I am now doing the following.

  • Ajax request is made to dialog.php
  • Server generates html and javascript that is specific to this dialog then encodes them as JSON
  • JSON is returned to client.
  • HTML is appended to the <body> then once this is rendered, the javascript is also appended into the DOM.

The javascript is executed automatically upon insertion and the dynamic dialog opens up.

Doing this has reduced the amount of javasript on my page dramatically however I am concerned about clean up of the inserted javascript.

Obviously once the dialog has been closed it is removed from the DOM using jQuery:

$('#dialog').remove();

The javascript is appended with an ID and I also remove this from the DOM via the same method.

However, as stated above, does using jQuery’s .remove() actually clean out the javascript from memory or does it simple remove the <script> element from the DOM?

If so, is there any way to clean this up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:13:43+00:00Added an answer on May 31, 2026 at 10:13 am

    No. Once a script is loaded, the objects and functions it defines are kept in memory. Removing a script element does not remove the objects it defines. This is in contrast to CSS files, where removing the element does remove the styles it defines. That’s because the new styles can easily be reflowed. Can you imagine how hard it would be to work out what a script tag created and how to remove it?

    EDIT: However, if you have a file that defines myFunction, then you add another script that redefines myFunction to something else, the new value will be kept. You can remove the old script tag if you want to keep the DOM clean, but that’s all removing it does.

    EDIT2: The only real way to “clean up” functions that I can think of is to have a JS file that basically calls delete window.myFunction for every possible object and function your other script files may define. For obvious reasons, this is a really bad idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says I want to remove the first 4 letters from a
Like the title says, how can i remove the spinwheel from a Panel? I
As the title says, is there a way to remove code from a view
As the title says, is it recommended to remove Data Row from Data Table
As title says, how do I call a java class method from a jsp,
Like the title says, my code basically does this: set proxy, test proxy, do
As the title says :) In my database the table I'm using has an
Basically as the title says when using Areas in ASP.NET MVC2.0 I've ended up
Possible Duplicate: PHP remove accents The title says most of it, but anyways... I
Title says what i'm trying to do. I can successfully generate an assembly if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.