Skip to content

Commit

Permalink
Avoid browser cache issues using last modified time (#2489)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdwebdesign authored Jan 14, 2023
2 parents 854e7e9 + 302a402 commit 9006c41
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 70 deletions.
2 changes: 1 addition & 1 deletion auditlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</div>
<!-- /.row -->

<script src="scripts/pi-hole/js/auditlog.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/auditlog.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion cname_records.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/customcname.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/customcname.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
4 changes: 2 additions & 2 deletions db_graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
</div>
</div>

<script src="scripts/vendor/daterangepicker.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/db_graph.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/daterangepicker.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/db_graph.js'); ?>"></script>
<?php
require 'scripts/pi-hole/php/footer.php';
?>
4 changes: 2 additions & 2 deletions db_lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
<!-- /.col -->
</div>

<script src="scripts/vendor/daterangepicker.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/db_lists.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/daterangepicker.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/db_lists.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
6 changes: 3 additions & 3 deletions db_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@
</div>
</div>
<!-- /.row -->
<script src="scripts/pi-hole/js/ip-address-sorting.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/daterangepicker.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/db_queries.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/ip-address-sorting.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/daterangepicker.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/db_queries.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<button type="button" id="debugBtn" class="btn btn-lg btn-primary btn-block">Generate debug log</button>
<pre id="output" style="width: 100%; height: 100%;" hidden></pre>

<script src="scripts/pi-hole/js/debug.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/debug.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
4 changes: 2 additions & 2 deletions dns_records.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
</div>
</div>

<script src="scripts/pi-hole/js/ip-address-sorting.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/customdns.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/ip-address-sorting.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/customdns.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion gravity.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<button type="button" id="gravityBtn" class="btn btn-lg btn-primary btn-block">Update</button>
<pre id="output" style="width: 100%; height: 100%;" hidden></pre>

<script src="scripts/pi-hole/js/gravity.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/gravity.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
6 changes: 3 additions & 3 deletions groups-adlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
</div>
</div>

<script src="scripts/vendor/bootstrap-select.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/bootstrap-toggle.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/groups-adlists.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-select.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-toggle.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/groups-adlists.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
8 changes: 4 additions & 4 deletions groups-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
</div>
</div>

<script src="scripts/vendor/bootstrap-select.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/bootstrap-toggle.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/ip-address-sorting.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/groups-clients.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-select.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-toggle.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/ip-address-sorting.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/groups-clients.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
6 changes: 3 additions & 3 deletions groups-domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
</div>
</div>

<script src="scripts/vendor/bootstrap-select.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/bootstrap-toggle.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/groups-domains.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-select.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-toggle.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/groups-domains.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
6 changes: 3 additions & 3 deletions groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
</div>
</div>

<script src="scripts/vendor/bootstrap-select.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/bootstrap-toggle.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/groups.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-select.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-toggle.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/groups.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
</div>
<!-- /.row -->

<script src="scripts/pi-hole/js/index.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/index.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion login.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@
<strong><a href="https://pi-hole.net/donate/" rel="noopener" target="_blank"><i class="fa fa-heart text-red"></i> Donate</a></strong> if you found this useful.
</div>
</div>
<script src="scripts/pi-hole/js/footer.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/footer.js'); ?>"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/messages.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/messages.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
4 changes: 2 additions & 2 deletions network.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
</div>
<!-- /.row -->

<script src="scripts/pi-hole/js/ip-address-sorting.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/network.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/ip-address-sorting.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/network.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
4 changes: 2 additions & 2 deletions queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@
</div>
</div>
<!-- /.row -->
<script src="scripts/pi-hole/js/ip-address-sorting.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/queries.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/ip-address-sorting.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/queries.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion queryads.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<pre id="output" style="width: 100%; height: 100%;" hidden></pre>

<script src="scripts/pi-hole/js/queryads.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/queryads.js'); ?>"></script>
<?php
require 'scripts/pi-hole/php/footer.php';
?>
2 changes: 1 addition & 1 deletion scripts/pi-hole/php/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@

</div>
<!-- ./wrapper -->
<script src="scripts/pi-hole/js/footer.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/footer.js'); ?>"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions scripts/pi-hole/php/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ function checkfile($filename)
return '/dev/null';
}

// Avoid browser caching old versions of a file, using the last modification time
// Receive the file URL (without "/admin/");
// Return the string containin URL + "?v=xxx", where xxx is the last modified time of the file.
function fileversion($url)
{
$filename = $_SERVER['DOCUMENT_ROOT'].'/admin/'.$url;
if (file_exists($filename)) {
$ver = filemtime($filename);
}

return $url.'?v='.$ver;
}

// Credit: http://php.net/manual/en/function.hash-equals.php#119576
if (!function_exists('hash_equals')) {
function hash_equals($known_string, $user_string)
Expand Down
59 changes: 28 additions & 31 deletions scripts/pi-hole/php/header.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
$scriptname = basename($_SERVER['SCRIPT_FILENAME']);
$hostname = gethostname() ? gethostname() : '';

// Create cache busting version
$cacheVer = filemtime(__FILE__);
?>
<!DOCTYPE html>
<!--
Expand Down Expand Up @@ -53,49 +50,49 @@

<!-- Theme fonts -->
<?php if ($theme == 'lcars') { ?>
<link rel="stylesheet" href="style/vendor/fonts/ubuntu-mono/ubuntu-mono.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/fonts/antonio/antonio.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/fonts/ubuntu-mono/ubuntu-mono.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/fonts/antonio/antonio.css'); ?>">
<?php } else { ?>
<link rel="stylesheet" href="style/vendor/SourceSansPro/SourceSansPro.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/SourceSansPro/SourceSansPro.css'); ?>">
<?php } ?>

<!-- Common styles -->
<link rel="stylesheet" href="style/vendor/bootstrap/css/bootstrap.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/bootstrap/css/bootstrap.min.css'); ?>">
<?php if ($auth) { ?>
<link rel="stylesheet" href="style/vendor/datatables.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/datatables_extensions.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/daterangepicker.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/datatables.min.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/datatables_extensions.min.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/daterangepicker.min.css'); ?>">
<?php } ?>
<link rel="stylesheet" href="style/vendor/AdminLTE.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/select2.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/AdminLTE.min.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/select2.min.css'); ?>">

<?php if (in_array($scriptname, array('groups.php', 'groups-adlists.php', 'groups-clients.php', 'groups-domains.php'))) { ?>
<!-- Group management styles -->
<link rel="stylesheet" href="style/vendor/animate.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/bootstrap-select.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/bootstrap-toggle.min.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/animate.min.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/bootstrap-select.min.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/vendor/bootstrap-toggle.min.css'); ?>">
<?php } ?>

<!-- Theme styles -->
<link rel="stylesheet" href="style/pi-hole.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/themes/<?php echo $theme; ?>.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/pi-hole.css'); ?>">
<link rel="stylesheet" href="<?php echo fileversion('style/themes/'.$theme.'.css'); ?>">

<noscript><link rel="stylesheet" href="style/vendor/js-warn.css?v=<?php echo $cacheVer; ?>"></noscript>
<noscript><link rel="stylesheet" href="<?php echo fileversion('style/vendor/js-warn.css'); ?>"></noscript>

<!-- scripts -->
<script src="scripts/vendor/jquery.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="style/vendor/bootstrap/js/bootstrap.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/adminlte.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/bootstrap-notify.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/jquery.min.js'); ?>"></script>
<script src="<?php echo fileversion('style/vendor/bootstrap/js/bootstrap.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/adminlte.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/bootstrap-notify.min.js'); ?>"></script>
<?php if ($auth) { ?>
<script src="scripts/vendor/select2.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/datatables.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/datatables.select.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/datatables.buttons.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/moment.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/chart.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/vendor/chartjs-adapter-moment.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/select2.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/datatables.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/datatables.select.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/datatables.buttons.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/moment.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/chart.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/chartjs-adapter-moment.js'); ?>"></script>
<?php } ?>
<script src="style/vendor/font-awesome/js/all.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/utils.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('style/vendor/font-awesome/js/all.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/utils.js'); ?>"></script>
</head>
4 changes: 2 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1462,8 +1462,8 @@
</div>
</div>

<script src="scripts/vendor/jquery.confirm.min.js?v=<?php echo $cacheVer; ?>"></script>
<script src="scripts/pi-hole/js/settings.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/vendor/jquery.confirm.min.js'); ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/settings.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion taillog-FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<label for="chk2">Automatic scrolling on update</label>
</div>

<script src="scripts/pi-hole/js/taillog-FTL.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/taillog-FTL.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down
2 changes: 1 addition & 1 deletion taillog.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<label for="chk2">Automatic scrolling on update</label>
</div>

<script src="scripts/pi-hole/js/taillog.js?v=<?php echo $cacheVer; ?>"></script>
<script src="<?php echo fileversion('scripts/pi-hole/js/taillog.js'); ?>"></script>

<?php
require 'scripts/pi-hole/php/footer.php';
Expand Down

0 comments on commit 9006c41

Please sign in to comment.