Patch 3184242 pour Drupal 9.5.9
The snippet can be accessed without any authentication.
Authored by
Pierre
Pas publié dans https://www.drupal.org/project/drupal/issues/3184242 parce que le patch en cours vise Drupal 10
drupal-3184242-9.5.9.patch 6.57 KiB
diff --git a/core/assets/scaffold/files/htaccess b/core/assets/scaffold/files/htaccess
index 1575c51f3d..1d6d5bfe3e 100644
--- a/core/assets/scaffold/files/htaccess
+++ b/core/assets/scaffold/files/htaccess
@@ -155,11 +155,21 @@ AddEncoding gzip svgz
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
<IfModule mod_headers.c>
+ # Serve brotli compressed CSS files if they exist and the client accepts brotli.
+ RewriteCond %{HTTP:Accept-encoding} br
+ RewriteCond %{REQUEST_FILENAME}\.br -s
+ RewriteRule ^(.*)\.css $1\.css\.br [QSA]
+
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*css_[a-zA-Z0-9-_]+)\.css$ $1\.css\.gz [QSA]
+ # Serve brotli compressed JS files if they exist and the client accepts brotli.
+ RewriteCond %{HTTP:Accept-encoding} br
+ RewriteCond %{REQUEST_FILENAME}\.br -s
+ RewriteRule ^(.*)\.js $1\.js\.br [QSA]
+
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
@@ -168,6 +178,8 @@ AddEncoding gzip svgz
# Serve correct content types, and prevent double compression.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1,E=no-brotli:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
+ RewriteRule \.css\.br - [T=text/css,E=no-gzip:1,E=no-brotli:1]
+ RewriteRule \.js\.br - [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
@@ -175,6 +187,13 @@ AddEncoding gzip svgz
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
+
+ <FilesMatch "(\.js\.br|\.css\.br)$">
+ # Serve correct encoding type.
+ Header set Content-Encoding br
+ # Force proxies to cache compressed & non-compressed css/js files separately.
+ Header append Vary Accept-Encoding
+ </FilesMatch>
</IfModule>
</IfModule>
diff --git a/core/lib/Drupal/Core/Asset/AssetDumper.php b/core/lib/Drupal/Core/Asset/AssetDumper.php
index 6f90f8f556..7df4c7173f 100644
--- a/core/lib/Drupal/Core/Asset/AssetDumper.php
+++ b/core/lib/Drupal/Core/Asset/AssetDumper.php
@@ -70,6 +70,16 @@ public function dump($data, $file_extension) {
return FALSE;
}
}
+ if (extension_loaded('brotli') && \Drupal::config('system.performance')->get($file_extension . '.brotli')) {
+ try {
+ if (!file_exists($uri . '.br') && !$this->fileSystem->saveData(brotli_compress($data, 11, BROTLI_TEXT), $uri . '.br', FileSystemInterface::EXISTS_REPLACE)) {
+ return FALSE;
+ }
+ }
+ catch (FileException $e) {
+ return FALSE;
+ }
+ }
return $uri;
}
diff --git a/core/modules/system/config/install/system.performance.yml b/core/modules/system/config/install/system.performance.yml
index 11392bd1e4..06de268308 100644
--- a/core/modules/system/config/install/system.performance.yml
+++ b/core/modules/system/config/install/system.performance.yml
@@ -4,6 +4,7 @@ cache:
css:
preprocess: true
gzip: true
+ brotli: false
fast_404:
enabled: true
paths: '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'
@@ -12,4 +13,5 @@ fast_404:
js:
preprocess: true
gzip: true
+ brotli: false
stale_file_threshold: 2592000
diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml
index 3e61a0036b..fb8fa5531a 100644
--- a/core/modules/system/config/schema/system.schema.yml
+++ b/core/modules/system/config/schema/system.schema.yml
@@ -153,7 +153,10 @@ system.performance:
label: 'Aggregate CSS files'
gzip:
type: boolean
- label: 'Compress CSS files'
+ label: 'Compress CSS files with gzip'
+ brotli:
+ type: boolean
+ label: 'Compress CSS files with Brotli'
fast_404:
type: mapping
label: 'Fast 404 settings'
@@ -179,7 +182,10 @@ system.performance:
label: 'JavaScript preprocess'
gzip:
type: boolean
- label: 'Compress JavaScript files.'
+ label: 'Compress JavaScript files with gzip'
+ brotli:
+ type: boolean
+ label: 'Compress JavaScript files with Brotli'
stale_file_threshold:
type: integer
label: 'Stale file threshold'
diff --git a/core/modules/system/tests/src/Kernel/Migrate/d6/MigrateSystemConfigurationTest.php b/core/modules/system/tests/src/Kernel/Migrate/d6/MigrateSystemConfigurationTest.php
index 5b53850eb4..4dd40d1671 100644
--- a/core/modules/system/tests/src/Kernel/Migrate/d6/MigrateSystemConfigurationTest.php
+++ b/core/modules/system/tests/src/Kernel/Migrate/d6/MigrateSystemConfigurationTest.php
@@ -74,6 +74,7 @@ class MigrateSystemConfigurationTest extends MigrateDrupal6TestBase {
'preprocess' => FALSE,
// gzip is not handled by the migration.
'gzip' => TRUE,
+ 'brotli' => FALSE,
],
// fast_404 is not handled by the migration.
'fast_404' => [
@@ -86,6 +87,7 @@ class MigrateSystemConfigurationTest extends MigrateDrupal6TestBase {
'preprocess' => FALSE,
// gzip is not handled by the migration.
'gzip' => TRUE,
+ 'brotli' => FALSE,
],
// stale_file_threshold is not handled by the migration.
'stale_file_threshold' => 2592000,
diff --git a/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateSystemConfigurationTest.php b/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateSystemConfigurationTest.php
index 80a591fdd1..5c7b7e3e38 100644
--- a/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateSystemConfigurationTest.php
+++ b/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateSystemConfigurationTest.php
@@ -75,6 +75,7 @@ class MigrateSystemConfigurationTest extends MigrateDrupal7TestBase {
'preprocess' => TRUE,
// gzip is not handled by the migration.
'gzip' => TRUE,
+ 'brotli' => FALSE,
],
// fast_404 is not handled by the migration.
'fast_404' => [
@@ -87,6 +88,7 @@ class MigrateSystemConfigurationTest extends MigrateDrupal7TestBase {
'preprocess' => FALSE,
// gzip is not handled by the migration.
'gzip' => TRUE,
+ 'brotli' => FALSE,
],
// stale_file_threshold is not handled by the migration.
'stale_file_threshold' => 2592000,
Please register or sign in to comment