How to unload a javascript from an html?

前端 未结 7 2076
予麋鹿
予麋鹿 2020-11-28 10:27

How can I unload a JavaScript resource with all its defined objects from the DOM?

Im developing a simple framework that enables to load html fragments into a \"main\

相关标签:
7条回答
  • 2020-11-28 11:22

    Was researching for something like that myself and thought I'll post my findings

    1. Wrap your stuff in a global namespace in js file so it can be removed easily, ie var stuff = { blabla: 1, method: function(){} };

    2. When you need to get rid of it, simply set stuff = {}, or null even

    3. Remove script tag from page

    *** If you use requirejs - require js remove definition to force reload

    Note: as long as you don't reference modules inside the namespace from anywhere else everything will be collected by GC and you are good to go.

    0 讨论(0)
提交回复
热议问题