There are several solutions for this. If you want to refresh the page, you don’t really need JavaScript, the browser can do it for you if you add this tag meta
to your tag head
.
<meta http-equiv="refresh" content="30"/>
The browser will refresh the page every 30 seconds.
If you really want to do this using JavaScript, then you can refresh the page every 30 seconds using location.reload()
( docs ) inside setTimeout()
:
setTimeout(function() {
location.reload();
}, 30000);
Otherwise, if you do not need to refresh the entire page, but only part of it, I think that calling Ajax will be the most efficient way.
source
share