$ .empty()足够大的ajaxy应用程序吗? [英] Is $.empty() enough for big ajaxy apps?

查看:54
本文介绍了$ .empty()足够大的ajaxy应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在开发应用程序,因为它有点太大我想到了改善内存管理的方法,因为应用程序主要在Javascipt上运行。因此,每次单击导航项时,我都会将jquery称为空,然后通过ajax显示html。例如:

Been working on an App and since it's getting a bit too big I've thinking of ways to improve memory management since the app runs mostly on Javascipt. So every time a navigation item is clicked I would call the jquery empty then show the html via ajax. ex:

//$.ajaxSetup(); called before this
//$this is the attached element 
$.ajax({success:function(data){
    $this.empty().html(data.output).fadeIn(400);
    //more javascript stuff like loading tinymce or jquery ui
}});

这是否足以防止内存泄漏?我不完全确定空的是什么,但我假设它删除了该div中的所有DOM元素以及任何其他对象和事件?顺便说一句。你可以在这里找到这个应用程序 http://webproposalgenerator.com/ http://webproposalgenerator.com/demo

is this enough to prevent memory leaks? I'm not entirely sure what empty does but I'm assuming it removes all DOM elements within that div along with any other objects and events? btw. You can find the app here http://webproposalgenerator.com/ and http://webproposalgenerator.com/demo.

有关改善性能/安全性或任何反馈的任何提示一点都不胜感激。

any tips on improving the performance/security or any feedback at all would be greatly appreciated.

推荐答案

$。fn.empty 应该足够了,它会全部删除与元素关联的数据和事件,然后删除元素。它还在所有基于jquery-ui widget.js的小部件上调用 .widget(destroy)

$.fn.empty should be enough, it deletes all data and events associated to the elements and then deletes the elements. It also calls .widget("destroy") on all jquery-ui widget.js based widgets that are defined on those elements.

同样重要的是要注意jquery的 $。fn.html 方法调用 $。fn.empty()在附加html之前给定元素,因此,如果您使用 $。fn.html ,则不必调用 $ .fn.empty

It is also important to note that jquery's $.fn.html method calls $.fn.empty() on the given element before appending html, therefore, if you are using $.fn.html, you don't have to call $.fn.empty

这篇关于$ .empty()足够大的ajaxy应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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