How to delete script loaded by .getScript()
Asked Answered
T

2

7

When I load a script with .getScript('file.js') is there a way to do remove that script later? sort of like a clean where I say delete the js I loaded earlier

Tarnation answered 24/2, 2011 at 17:11 Comment(1)
See #1347397Dale
C
8

getScript doesn't "load" a script in the sense of keeping it around; it downloads the script from the server and runs it immediately. So there's no need to remove it.

However, any DOM objects that the script creates, or functions it defines, etc., will continue to exist. Removing these will require knowing specifically what they are; probably your best bet is to have your script define a function that deletes all of the things that the rest of the script creates.

Congruency answered 24/2, 2011 at 17:17 Comment(1)
Exactly...each object you load from an external script can have its own destruction routine.Godown
W
5

Unfortunately once the code has been executed you can't unexecute it.

However, if file.js creates DOM objects, you can delete those via delete object.name, and if you're bind()ing events you can always unbind() them.

Worser answered 24/2, 2011 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.