caching
This commit is contained in:
parent
744f4db361
commit
8d3b914433
18
index.php
18
index.php
@ -27,7 +27,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
|
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
|
||||||
<?php
|
<?php
|
||||||
include("table.php")
|
include("table.php");
|
||||||
|
liveresult_table($runners);
|
||||||
?>
|
?>
|
||||||
<footer>
|
<footer>
|
||||||
<h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3>
|
<h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3>
|
||||||
@ -36,12 +37,15 @@ include("table.php")
|
|||||||
<script>
|
<script>
|
||||||
function update() {
|
function update() {
|
||||||
const table = document.querySelector("table");
|
const table = document.querySelector("table");
|
||||||
const myRequest = new Request(`table.php`);
|
const request = new XMLHttpRequest();
|
||||||
fetch(myRequest)
|
request.onreadystatechange = function() {
|
||||||
.then((response) => response.text())
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
.then((text) => {
|
table.innerHTML = this.responseText;
|
||||||
table.innerHTML = text;
|
localStorage.setItem("ETag", this.getResponseHeader("ETag"));
|
||||||
});
|
}};
|
||||||
|
request.open("GET", "table.php?type=liveresultater");
|
||||||
|
request.setRequestHeader("If-None-Match", localStorage.getItem("ETag"));
|
||||||
|
request.send();
|
||||||
}
|
}
|
||||||
setInterval(update, 5*1000)
|
setInterval(update, 5*1000)
|
||||||
</script>
|
</script>
|
||||||
|
29
table.php
29
table.php
@ -12,7 +12,7 @@ if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|||||||
// If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache
|
// If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache
|
||||||
// So send a 304 Not Modified response header and exit
|
// So send a 304 Not Modified response header and exit
|
||||||
if($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
|
if($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
|
||||||
header('HTTP/1.1 304 Not Modified', true, 304);
|
http_response_code(304);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,8 +27,6 @@ class Runner
|
|||||||
|
|
||||||
function __construct($id, $name, $club, $course)
|
function __construct($id, $name, $club, $course)
|
||||||
{
|
{
|
||||||
//echo($id);
|
|
||||||
//echo($name);
|
|
||||||
if ($id == null) {
|
if ($id == null) {
|
||||||
$id = 0;
|
$id = 0;
|
||||||
$name = "";
|
$name = "";
|
||||||
@ -139,12 +137,7 @@ for ($i = 0; $i < count($timings); $i++) {
|
|||||||
$runner->set_split($line[0]-1, $time);
|
$runner->set_split($line[0]-1, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function registration_table($runners) {
|
||||||
if (!isset($query)){
|
|
||||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($query["type"] == "registrering"){
|
|
||||||
$matpost = $query["control"];
|
$matpost = $query["control"];
|
||||||
$runners_filtered = [];
|
$runners_filtered = [];
|
||||||
if ($query["filter"]) {
|
if ($query["filter"]) {
|
||||||
@ -194,7 +187,8 @@ if ($query["type"] == "registrering"){
|
|||||||
}
|
}
|
||||||
echo("</tbody>");
|
echo("</tbody>");
|
||||||
}
|
}
|
||||||
elseif ($query["type"] == "paameldte") {
|
|
||||||
|
function participants_table($runners) {
|
||||||
usort($runners, "cmp_course");
|
usort($runners, "cmp_course");
|
||||||
|
|
||||||
$kadaverløpere = 0;
|
$kadaverløpere = 0;
|
||||||
@ -226,7 +220,7 @@ elseif ($query["type"] == "paameldte") {
|
|||||||
}
|
}
|
||||||
echo("<table><tbody>");
|
echo("<table><tbody>");
|
||||||
}
|
}
|
||||||
else {
|
function liveresult_table($runners) {
|
||||||
usort($runners, "cmp");
|
usort($runners, "cmp");
|
||||||
usort($runners, "cmp_course");
|
usort($runners, "cmp_course");
|
||||||
$kadaver_table = "<table><thead>
|
$kadaver_table = "<table><thead>
|
||||||
@ -292,3 +286,16 @@ else {
|
|||||||
echo($kadaver_table);
|
echo($kadaver_table);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($query)){
|
||||||
|
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||||
|
if ($query["type"] == "registrering"){
|
||||||
|
registration_table($runners);
|
||||||
|
}
|
||||||
|
elseif ($query["type"] == "paameldte") {
|
||||||
|
participants_table($runners);
|
||||||
|
}
|
||||||
|
elseif ($query["type"] == "liveresultater") {
|
||||||
|
liveresult_table($runners);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user