clarify use of cache buster, avoid using regex

This commit is contained in:
El RIDO 2024-07-09 22:35:21 +02:00
parent 3c6df4573e
commit 4b6c8356f5
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
2 changed files with 4 additions and 5 deletions

View File

@ -69,10 +69,11 @@ class View
{ {
$sri = array_key_exists($file, $this->_variables['SRI']) ? $sri = array_key_exists($file, $this->_variables['SRI']) ?
' integrity="' . $this->_variables['SRI'][$file] . '"' : ''; ' integrity="' . $this->_variables['SRI'][$file] . '"' : '';
$suffix = preg_match('#\d.js$#', $file) == 0 ? // if the file isn't versioned (ends in a digit), add our own version
'?' . rawurlencode($this->_variables['VERSION']) : ''; $cacheBuster = ctype_digit(substr($file, -4, 1)) ?
'' : '?' . rawurlencode($this->_variables['VERSION']);
echo '<script ', $attributes, echo '<script ', $attributes,
' type="text/javascript" data-cfasync="false" src="', $file, ' type="text/javascript" data-cfasync="false" src="', $file,
$suffix, '"', $sri, ' crossorigin="anonymous"></script>', PHP_EOL; $cacheBuster, '"', $sri, ' crossorigin="anonymous"></script>', PHP_EOL;
} }
} }

View File

@ -1,7 +1,5 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use Exception;
use GlobIterator;
use Google\Cloud\Core\Exception\BadRequestException; use Google\Cloud\Core\Exception\BadRequestException;
use Google\Cloud\Core\Exception\NotFoundException; use Google\Cloud\Core\Exception\NotFoundException;
use Google\Cloud\Storage\Bucket; use Google\Cloud\Storage\Bucket;