How to remove script loaded by .getScript ()

When I load a script using .getScript('file.js') , is there a way to remove this script later? kind of clean where I say delete previously downloaded js

+4
source share
2 answers

getScript does not load the script in the sense of persistence; it downloads the script from the server and runs it immediately. Therefore, there is no need to remove it.

However, any DOM objects that the script creates, or its functions, etc., will continue to exist. To eliminate them, you need to know what they are; it is probably best for your script to define a function that removes everything that the rest of the script creates.

+7
source

Unfortunately, once the code has been executed, you cannot execute it.

However, if file.js creates DOM objects, you can delete them through delete object.name , and if you are bind() events, you can always unbind() them.

+5
source

Source: https://habr.com/ru/post/1341176/


All Articles