Problem/Motivation
Similar to the cloned parent #3191028: Website error Exception: Only file CSS assets can be optimized but with a twist...
Since upgrading to 10.2 we've been seeing these in the logs (maybe because we moved away from advagg to core's aggregation)
We are seeing cached pages calling aggregated assets from the past! That triggers errors in the log as such:
Exception: Only file CSS assets can be optimized. in Drupal\Core\Asset\CssOptimizer->optimize() (line 43 of core/lib/Drupal/Core/Asset/CssOptimizer.php).
The problem was that we *HAD* some assets that were type: external
AND minified: true
I fixed the problem by removing minified: true
. But here's the twist: because these cached pages return cached aggregate assets that have includes the library that still exists, they assume they should still be minified because they are in the URL.
Steps to reproduce
I took the failing asset path locally (don't need the file to be there for test, it's the include= that causes the issue)sites/default/files/css/css_LYCBGljzz7g174tLEdAJcO7-JDTovJeWZpQ-gEqd6Nk.css?delta=1&include=eJx1T4sOgzAI_KHWfpLByrBKHyvtnPv61cy4R7KEBO7gOLAxo5mvFfOmBrBLX2KLZD7qfpa_LWdjULJJQd94QUXAYEsV41EECEXZ3SHE7IHd42OAOA7AyvLlKLWUjV0ghffS8mLGXBNwd0BFMRJjX4AMFf8NgV4-hyTlSLkd8DvUwQz39wl2DLr56_bgm2t45y-rHlaVIANlSJOcq0-mqyHVgZ1MOH7r18mVgJse8fYEEqeHrA&language=en&theme=clf
Set a breakpoint herepublic/core/lib/Drupal/Core/Asset/CssOptimizer.php:43
And this asset which exists still, but is not meant to be minified anymore is causing the exception to be thrown.
$css_asset = {array[8]}
type = "external"
weight = {float} -199.999
group = {int} 100
data = "https://cdn.ubc.ca/clf/7.0.4/css/ubc-clf-full-bw.min.css"
version = "7.0.4"
media = "all"
preprocess = true
license = {array[3]}
This is the library as it is now in galactus.libraries.yml:
clf-cdn-fw-bw:
version: 7.0.4
css:
base:
https://cdn.ubc.ca/clf/7.0.4/css/ubc-clf-full-bw.min.css: { type: external }
dependencies:
- galactus/cdn-clf-js
Proposed resolution
Consider silently aborting the library include if it's external and not minified (anymore)