Remove or document restrictions on CssOptimizer::optimize()

Created on 8 October 2023, 11 months ago
Updated 10 October 2023, 11 months ago

Problem/Motivation

CssOptimizer::optimize() throws an exception if the asset is not a file assets with preprocessing enabled. JsOptimizer is the same. This is not documented on AssetOptimizerInterface, and it's probably not a necessary restriction.

The exception requires the calling to code to understand the internals of whether an asset can be optimised, and then avoid calling this function accordingly. These factors could change, even in a minor version.

It's not clear that this function should prevent external assets from be optimised. Although the CSS aggregation would only want to optimise file assets, other code using the service might be different. If a site wanted to send an email styled with CSS that was external and contained @import that's exactly what it would need.

Proposed resolution

  1. Allow optimising external assets, if preprocess is set. However let preprocess by FALSE by default (which is consistent with existing behaviour).
  2. Remove the exceptions. If preprocess is FALSE and so the asset cannot be optimised then this function should simply return the file contents. In this case, the optimised asset is equal to the original asset.

Other options:

  • Document the exception (better than nothing, but doesn't really solve the problem).

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component
Asset library 

Last updated 1 day ago

No maintainer
Created by

🇬🇧United Kingdom AdamPS

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024