your rotating banner system (/banners.php) is inefficient because it's impossible for users to cache these images in their browsers. everyone is constantly re-downloading previously-seen banners.
you can see if a file is already cached or is downloaded by refreshing a page (e.g.
https://leftypol.org/banners.php ) by checking http responses in firefox in the Network tab in Firefox Developer Tools (ctrl+shift+i) and seeing if it says "cached" under the "Transferred" column for the file
you can instead make it so twig serves the direct path to a random image from your banners folder instead of sending it to your inlined banners.php image file stream so that browsers can actually cache these images. this can speed up frequent visitors' page loads and reduce a bit of bandwidth per frequent visitor.
1. go to /inc/lib/Twig/Extensions/Extension/Tinyboard.php
2. add this line in that list of Twig extension functions:
new Twig_SimpleFunction('random_banner_url', 'twig_random_banner_url'),
(don't forget to put a comma at the end of that previous item or you'll get php error / blank page)
3. at the end of the file add this function definition:
function twig_random_banner_url() {
$path = dirname(__DIR__, 5) . '/banners/';
$isDirEmpty = true;
if (!file_exists($path)) {
return '/static/blank.gif';
}
$handle = opendir($path);
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$isDirEmpty = false;
break;
}
}
closedir($handle);
if (!$isDirEmpty) {
$files = scandir($path);
$files = array_diff($files, array('.', '..'));
return '/banners/' . $files[array_rand($files)];
}
return '/static/blank.gif';
}
4. go to /templates/index.html, and change
<img class="board_image" src="{{ config.url_banner }}"
to
Post too long. Click here to view the full text.