简体   繁体   English

Javascripts导致浏览器内存泄漏

[英]Javascripts causing browser memory leak

I have a Web app which is a monitoring tool. 我有一个Web应用程序,它是一个监视工具。 So someone it's going to keep it open on the browser all the day long. 所以有人会一整天都在浏览器上打开它。 The problem is I'm refreshing the index page each 3 min: 问题是我每3分钟刷新一次索引页面:

var auto_refresh = setTimeout( function () {
    $('#page-body').load('/Monitor/Index').fadeIn("slow");
}, 180000); 

And every time the app refreshes itself, it's loading 3 javascripts which I'm invoking on my layout: 每次应用程序刷新自己时,它都会加载3个我在我的布局上调用的javascripts:

<script type="text/javascript" src="@Url.Content("~/Scripts/script-core-v1.0.js")">
</script> 
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.dataTables.js")"> 
</script>  
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.sparkline.js")">
</script>

So, my browser keeps getting bigger and bigger every time the app refreshes, and I think the main reason are those scripts. 因此,每次应用刷新时,我的浏览器都会变得越来越大,我认为主要原因是那些脚本。

How can I avoid this problem? 我该如何避免这个问题? Thanks! 谢谢!

Load a specific part of that page, not the whole thing: 加载该页面的特定部分,而不是整个页面:

$('#page-body').load('/Monitor/Index body')
                                     ^^^^

That's a selector on the end so you can target a specific element. 这是最终的选择器,因此您可以定位特定元素。

When you don't provide a selector, the whole page is loaded (scripts and all). 如果不提供选择器,则会加载整个页面(脚本和所有页面)。 When you provide a selector, the <script> tags are stripped. 提供选择器时,将删除<script>标记。

Also, your browser probably isn't leaking memory. 此外,您的浏览器可能没有泄漏内存。 Your website is just consuming it all. 您的网站只是消耗它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM