From f52cbee10a00cdbddfb760c9fcc6a8a29121a905 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 5 Feb 2024 11:34:53 -0800 Subject: [PATCH] Add support for .js.gz and .css.gz Resolves #14243 --- CHANGELOG-WIP.md | 3 +++ src/helpers/Template.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index d05705b02bb..e6a534b26e9 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -2,3 +2,6 @@ ### Administration - The `queue/run` command now supports a `--job-id` option. + +### Development +- The `{% js %}` and `{% css %}` tags now support `.js.gz` and `.css.gz` URLs. ([#14243](https://github.com/craftcms/cms/issues/14243)) diff --git a/src/helpers/Template.php b/src/helpers/Template.php index 2ff93e494f8..dcf4e5b77a5 100644 --- a/src/helpers/Template.php +++ b/src/helpers/Template.php @@ -270,7 +270,7 @@ private static function _profileToken(string $type, string $name, int $count): s public static function css(string $css, array $options = [], ?string $key = null): void { // Is this a CSS file? - if (preg_match('/^[^\r\n]+\.css$/i', $css) || UrlHelper::isAbsoluteUrl($css)) { + if (preg_match('/^[^\r\n]+\.css(\.gz)?$/i', $css) || UrlHelper::isAbsoluteUrl($css)) { Craft::$app->getView()->registerCssFile($css, $options, $key); } else { Craft::$app->getView()->registerCss($css, $options, $key); @@ -291,7 +291,7 @@ public static function css(string $css, array $options = [], ?string $key = null public static function js(string $js, array $options = [], ?string $key = null): void { // Is this a JS file? - if (preg_match('/^[^\r\n]+\.js$/i', $js) || UrlHelper::isAbsoluteUrl($js)) { + if (preg_match('/^[^\r\n]+\.js(\.gz)?$/i', $js) || UrlHelper::isAbsoluteUrl($js)) { Craft::$app->getView()->registerJsFile($js, $options, $key); } else { $position = $options['position'] ?? View::POS_READY;