🚨 CSS-Caching bei localhost verhindern
authorMalte Bublitz <malte@rolltreppe3.de>
Fri, 2 May 2025 19:45:16 +0000 (21:45 +0200)
committerMalte Bublitz <malte@rolltreppe3.de>
Fri, 2 May 2025 19:45:16 +0000 (21:45 +0200)
Verhindert Probleme beim Debugging, indem bei Zugriff via localhost
die aktuelle Unix-Zeit als GET-Parameter an die Stylesheet- und
Icon-URLs angehängt wird.

template.inc.php

index 6a949fb02ad96f432d244fafd280ba8439477a17..7e1fcdba34779a53c8f04cfcd26a361a75601a21 100644 (file)
@@ -28,6 +28,16 @@ $i = array_rand($search_placeholders);
 $placeholder = $search_placeholders[$i];
 unset($i);
 
+
+/**
+ * Append Unix Time to CSS files to force reloading while debugging
+ */
+$css_query_string = "";
+if (in_array($_SERVER["REMOTE_ADDR"], array("::0", "127.0.0.1"))) {
+       $unixtime = date("U");
+       $css_query_string = "?unixtime=" . $unixtime;
+}
+
 ?><!DOCTYPE html>
 <html lang="<?=$Data["Meta"]["Lang"]?>">
        <head>
@@ -46,13 +56,13 @@ unset($i);
                <link rel="author" type="text/plain" href="https://malte70.de/humans.txt">
                <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/dialog-polyfill/0.4.9/dialog-polyfill.min.css">
 <?php foreach ($Data["Meta"]["Stylesheets"] as $css): ?>
-       <?php if (!is_array($css)): ?>
-               <link rel="stylesheet" type="text/css" href="<?=$css?>">
-       <?php else: ?>
-               <link rel="stylesheet" type="text/css" media="<?=$css[1]?>" href="<?=$css[0]?>">
-       <?php endif; ?>
+<?php  if (!is_array($css)): ?>
+               <link rel="stylesheet" type="text/css" href="<?=$css.$css_query_string?>">
+<?php  else: ?>
+               <link rel="stylesheet" type="text/css" media="<?=$css[1]?>" href="<?=$css[0].$css_query_string?>">
+<?php  endif; ?>
 <?php endforeach; ?>
-               <link rel="icon" type="image/png" href="<?=$Data["Meta"]["Icon"]?>" sizes="64x64">
+               <link rel="icon" type="image/png" href="<?=$Data["Meta"]["Icon"].$css_query_string?>" sizes="64x64">
                <!--[if IE]><script>document.charset="<?=$Data["Meta"]["Charset"]?>";</script><![endif]-->
        </head>
        <body id="top">