Skip to content

Commit

Permalink
Add support for .js.gz and .css.gz
Browse files Browse the repository at this point in the history
Resolves #14243
  • Loading branch information
brandonkelly committed Feb 5, 2024
1 parent 5cde6dd commit f52cbee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions src/helpers/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit f52cbee

Please sign in to comment.