]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix Cache-Control header of non-versioned assets 37249/head
authorNicolas Guichard <nicolas@guichard.eu>
Thu, 2 Mar 2023 17:38:04 +0000 (18:38 +0100)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Wed, 15 Mar 2023 23:14:34 +0000 (23:14 +0000)
Non-cache-busted assets such as /dist/core-main.js also matched the
regex meant for cache-busted assets (note the ? at the end of the
regex).
The FilesMatch directive for cache-busted assets coming after the
non-cache-busted version all assets actually got the immutable flag
in their Cache-Control header. This caused client-side errors on
updates.

Query strings are not actually passed to FilesMatch directives so we
need another way to tell cache-busted/versionned assets apart from
non-versioned assets, here using If/Else directives.

Signed-off-by: Nicolas Guichard <nicolas@guichard.eu>
.htaccess

index dd0fce231e84b849df59e4d8de1756214246a33d..956e29ea7c40f20ed98d920090932dd9183ee167 100644 (file)
--- a/.htaccess
+++ b/.htaccess
 
   # Add cache control for static resources
   <FilesMatch "\.(css|js|svg|gif|png|jpg|ico|wasm|tflite)$">
-    Header set Cache-Control "max-age=15778463"
-  </FilesMatch>
-
-  <FilesMatch "\.(css|js|svg|gif|png|jpg|ico|wasm|tflite)(\?v=.*)?$">
-    Header set Cache-Control "max-age=15778463, immutable"
+    <If "%{QUERY_STRING} =~ /(^|&)v=/">
+      Header set Cache-Control "max-age=15778463, immutable"
+    </If>
+    <Else>
+      Header set Cache-Control "max-age=15778463"
+    </Else>
   </FilesMatch>
 
   # Let browsers cache WOFF files for a week