Does jQuery .remove() clear out loaded javascript when it is used to remove a script tag? -


as title says, if remove script tag dom using:

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

does javascript remain in memory or cleaned?

or... misunderstanding way in browsers treat javascript? quite possible.

for interested in reason asking see below:

i moving common javascript interactions static script files dynamically generated ones in php. loaded on demand when user requires them.

the reason doing in order move logic serverside , and run small script, returned server, clientside. rather have large script contains huge amount of logic, clientside.

this similar approach facebook does...

facebook talks frontend javascript

if take simple dialog instance. rather generating html in javascript, appending dom, using jqueryui's dialog widget load it, doing following.

  • ajax request made dialog.php
  • server generates html , javascript specific dialog encodes them json
  • json returned client.
  • html appended <body> once rendered, javascript appended dom.

the javascript executed automatically upon insertion , dynamic dialog opens up.

doing has reduced amount of javasript on page dramatically concerned clean of inserted javascript.

obviously once dialog has been closed removed dom using jquery:

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

the javascript appended id , remove dom via same method.

however, stated above, using jquery's .remove() clean out javascript memory or simple remove <script> element dom?

if so, there way clean up?

no. once script loaded, objects , functions defines kept in memory. removing script element not remove objects defines. in contrast css files, removing element remove styles defines. that's because new styles can reflowed. can imagine how hard work out script tag created , how remove it?

edit: however, if have file defines myfunction, add script redefines myfunction else, new value kept. can remove old script tag if want keep dom clean, that's removing does.

edit2: real way "clean up" functions can think of have js file calls delete window.myfunction every possible object , function other script files may define. obvious reasons, bad idea.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -