Reputation: 784
I've build a web app using node.js to display information to our users. However I'm seeing an unhealthy increase in the memory usage every time the page is refreshed (location.reload()
).
on first load it's 425MB, 787MB on the 2nd, 1075MB on the 3rd, 1350mb on the 4th etc... I've seen it climb to 5/6GBs
The only way to fix this is to close the tab and start from a new tab.
I can't see any increase while the page is sat idle or if you navigate round the page. It's like chrome is keeping the old page every time the page is reloaded. I have tried turning caching off from the dev tools but that didn't do anything. I've tried looking at the memory dev tools but I can't really make heads or tails of it.
is there a solution to this?
Upvotes: 5
Views: 2097
Reputation: 382
It's a problem with Google Chrome since at least 2016
You can use this workaround made in the linked 2016 question:
window.addEventListener('unload', function () {
document.documentElement.innerHTML = '';
});
And add the following metatags to limit the browser from caching the site.
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
Upvotes: 1