Just The Code Please

How to reload a page using Javascript

January 16th 2024

Summary

Here's a useful function. Sometimes we need to refresh a page using Javascript. This function can be called whenever you need it.

The Code

Javascript
function pageReload(emptyCache) {
    const isBool = emptyCache === true || emptyCache === false;// I like to sanitize inputs 
    if(isBool) {
        window.location.reload(emptyCache);
    } else {
        window.location.reload();
    }
}

setTimeout(() => {
  pageReload(true);
}, 3000);