Переглянути джерело

clarify use of cache buster, avoid using regex

El RIDO 2 роки тому
батько
коміт
4b6c8356f5
2 змінених файлів з 4 додано та 5 видалено
  1. 4 3
      lib/View.php
  2. 0 2
      tst/Bootstrap.php

+ 4 - 3
lib/View.php

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

+ 0 - 2
tst/Bootstrap.php

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