Upon a certain user interaction (a button click) I try to dynamically load a CSS file and a script file in my webpage and it worked fine. The CSS files bring in a few styles which get applied to the webpage. In the Javascript file, I have put some code inside a setInterval() which gets executed from an IIFY so that the code can run infinitely at a 1-second interval.
But when I tried to unload(remove) them, the CSS file gets removed easily but the script file is creating a problem. By removing <link rel="stylesheet" href="res/demo.css">
from the index.html file, the styles brought in by it gets removed from index.html also. By removing the <script src="res/demo.js"></script>
the underlying code keeps on running.
Sample code in the GIT repo:
https://github.com/anirbannath/loading-unloading-css-js.git
How can I stop the scripts and flush out the memory it takes other than refreshing the page entirely?