I have a chunk of code that causes a graph that monitors a graph to update periodically and is displayed with a raspberry pi, but the problem I'm having is because of the Pi's limited memory, Chromium dies because it run out of memory. I think this is because when the image updates, it saves the older images somewhere. I've tried using JS to delete the image and create a new one with an updated image, but it didn't work. I'm not too familiar with Javascript so I wasn't sure if I was making a rookie mistake or something. Here is the code:
<script type= "text/javascript">
var graph = "http://www.example.com";
function preload()
{
try
{
var buffer = new Image();
buffer.src = graph;
buffer.onload = function()
{
while (1)
{
setTimeout(preload, 1000);
document.getElementById('graph').src = buffer.src;
}
}
}
catch(err)
{
txt = "Error\n" + err.message;
alert(txt);
}
}
preload()
</script>
And the HTML for the image is:
<img src= "http://www.example.com" id=graph width=1015
height=275 frameborder="0" onload="preload()" style="display: block;
margin-left: auto; margin-right: auto;" align="bottom"/>
Here is a vastly simplified script for you - your loop made no sense at all and there is no Ajax in your code
var graph = "https://zabbix.tulsahpc.org/signage/sign.png",tId;
window.onload=function() {
tId=setInterval(function() {
document.getElementById('graph').src = graph+new Date().getTime();// avoid cache
},10000);// reload every 10 secs
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.