JSFiddle - React, Tailwind, and code Playground

by Rich Costello

HTML

<!DOCTYPE html>
<html>
<head>
<title>title</title>
<script type="text/javascript">
function fn() { //function that sometimes takes a long time
    show_loader();
    var data;
    for(var i = 0; i < 100000000; i++) {
        data = i/2+3+4+5;
        if(data > 1000) {
            data = 1223;
        }
        if(data < 0) {
            data = -1;
        }
    }
    hide_loader();//if you remove this line the loader will show after the execution
    
}
function show_loader() {
    document.getElementById('loader').style.visibility = "visible";
}
function hide_loader() {
    document.getElementById('loader').style.visibility = "hidden";
}
</script>

</head>
<body>
<div id="container">
    <div id="content">
        <input type="button" value="Compress Code" id="compress_button" onclick="show_loader(); setTimeout(fn, 8000);" /><div id="loader" style="visibility:hidden;"><img src="https://dev-oregon-cvrp.pantheonsite.io/sites/default/files/oregon-loading.gif" width="300" height="300" /></div>
    </div>
</div>

</body>
</html>