Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Auto Refresh Page on change?

Started by Snack 8 years ago · 1 replies · 1494 views
8 years ago

Hello there!
I am right now looking for a plugin, which automatically refreshes the page when something changes, as I am using an external program to modify my files. Any ideas?

8 years ago

You don't need a plugin for that, just use straight JS:

JS
    function get_page(url)
    {
        xmlhttp=new XMLHttpRequest();
        xmlhttp.open("GET", url, false);
        xmlhttp.send();
        return xmlhttp.responseText;
    }

    var html = get_page(window.location.href);

    setInterval(function(){
        if(html != get_page(window.location.href)){
            location.reload();
        }
    }, 5000);

The code above will check for changes every 5 seconds and reload if it detects any.

last edited 03/28/18 by P. Fighter

Suggested topics

Topic Participants Replies Views Activity
Plugins · by complanar, 2 weeks ago
2 250 4 days ago
Plugins · by Vladimir Novak, 1 month ago
3 594 1 month ago
Plugins · by Mathieu Lecouturier, 2 months ago
3 416 2 months ago
Plugins · by Slebeig, 2 months ago
1 530 2 months ago
Plugins · by Rene, 3 months ago
2 731 3 months ago