卸载用getScript加载的文件? [英] Unload files loaded with getScript?

查看:81
本文介绍了卸载用getScript加载的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用$ .getScript,我可以动态加载js文件。是否可以卸载这些文件中的某些文件?

With $.getScript I can load js files on the fly. Is it possible to "unload" some of these files ?

我有一个基于Ajax的管理面板。我有3个部分。单击每个部分时,我只想加载与之关联的文件。切换到另一部分时,我要卸载不必要的文件。

I have a ajax-based administrative panel. I have 3 sections. When clicking on each section I want to load only the files that are associated with it. When switching to another section I want to unload unnecessary files.

推荐答案

卸载(如果确实是 可能,在这里没有多大意义。让我们退后一步,看看为什么不要加载所有以以下内容开头的文件:

"Unloading", if it were really possible, wouldn't make much sense here. Let's take a step back and look at why you don't load all the files to begin with:


  • 它们是另一个HTTP请求和X个字节,如果您不需要它们,请不要获取它们

  • 它们具有不良影响-您不希望脚本X发生什么在这里

现在从另一侧看一下,您已经加载了它们,这意味着上面的已经发生了,您支付了获取它们的要求费用以及它们已经完成的工作。另外,他们在页面上产生的效果不能普遍撤销。仅删除< script> 并不会删除其声明的功能,其附加的事件处理程序等。

Now look at it from the other side, you have loaded them, which means both of the above have already happened, you paid the request cost of getting them and what they've done. Also, what effect they had on the page can't be generically undone. Just by removing a <script> doesn't remove the functions it declared, event handlers it attached, etc.

简而言之,为什么要卸载?如果要删除效果,那不是一件容易的事,无论如何也不是通用的。如果要简化页面...在这里没有任何好处,实际上您将承担删除元素的成本,而对JavaScript方面的客户端没有好处。

In short, why are you trying to unload? If it's to remove the effects, well that one's not easy, not in a generic way anyway. If it's to lighten the page...there's no benefit here, you'll actually just incur the cost of removing the element, with no benefit for the client on the JavaScript side of things.

这篇关于卸载用getScript加载的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆