Skip to content

Commit

Permalink
fix: issue with minify() and external assets like typekit
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Mar 27, 2023
1 parent 72d8968 commit c2014fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public function forceRecompile()
public function getFile($file, $forcePath = false)
{
if (strpos($file, "//") === 0) return $file;
if (strpos($file, "https://") === 0) return $file;
if (strpos($file, "http://") === 0) return $file;
if (strpos($file, "https://") === 0) return $file;
$file = Paths::normalizeSeparators($file);

Expand Down
11 changes: 11 additions & 0 deletions classes/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public function hasPostCss($markup): bool
return false;
}

public function isExternal()
{
if (strpos($this->path, "http://") === 0) return true;
if (strpos($this->path, "https://") === 0) return true;
if (strpos($this->path, "//") === 0) return true;
return false;
}

public function rockfrontend(): RockFrontend
{
return $this->wire->modules->get('RockFrontend');
Expand All @@ -87,6 +95,9 @@ public function setPath($path)
$this->path = $rockfrontend->getFile($path, true);
$this->url = $rockfrontend->url($path);

// early exit for external files
if ($this->isExternal()) return;

// if path and url are the same that means that we requested a file that does not exist
// in that case we prepend the root path to the url
if ($this->path and $this->path == $this->url) {
Expand Down
2 changes: 2 additions & 0 deletions classes/AssetsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function minifyAsset(Asset $asset): Asset
public function minifyAuto(Asset $asset): Asset
{
if (!$this->rockfrontend()->isEnabled('minify')) return $asset;
if ($asset->isExternal()) return $asset;

// check file type
if ($asset->ext == 'js') $search = ".min.js";
Expand Down Expand Up @@ -155,6 +156,7 @@ public function minifyAuto(Asset $asset): Asset
public function minifyForced(Asset $asset): Asset
{
if ($asset instanceof AssetComment) return $asset;
if ($asset->isExternal()) return $asset;
if ($asset->minify === false) return $asset;
if ($asset->minify === 'auto' and !$this->minify) return $asset;
if (substr($asset->path, -8) === '.min.css') return $asset;
Expand Down

0 comments on commit c2014fa

Please sign in to comment.