1. Reference: The same CSS file (with equal Etags) causes differences in the web interface due to differences in the response Content-Type. I found that the response Content-Type is implemented based on mime_content_type — Detects the MIME type of a file, which is ultimately implemented based on Mime-type Detection league/mime-type-detection league/mime-type-detection. It detects by content, falling back to detection by extension. See Figure 1.

PHP
use League\MimeTypeDetection\ExtensionMimeTypeDetector;
$this->detector = new ExtensionMimeTypeDetector();
Log::info(
$return['asset_key'],
[
$return['asset_key'],
$this->detector->detectMimeTypeFromPath($fullPath),
]
);
Plaintext
[2023-05-18 14:00:04] local.INFO: apps/internal/code-display/blocks/code-display.blade.php [
"apps/internal/code-display/blocks/code-display.blade.php",
"application/x-httpd-php"
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/.env.local [
"apps/internal/comment/.env.local",
null
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/app.json [
"apps/internal/comment/app.json",
"application/json"
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/assets/app.6e10b7.css [
"apps/internal/comment/assets/app.6e10b7.css",
"text/css"
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/assets/app.f8ed5d.js [
"apps/internal/comment/assets/app.f8ed5d.js",
"application/javascript"
]
[2023-05-18 14:00:05] local.INFO: apps/internal/custom-button/assets/images/ali-express-large.8fdc24.png [
"apps/internal/custom-button/assets/images/ali-express-large.8fdc24.png",
"image/png"
]
[2023-05-18 14:00:07] local.INFO: apps/internal/sharing-incentives/assets/images/sparkles.a0d182.jpg [
"apps/internal/sharing-incentives/assets/images/sparkles.a0d182.jpg",
"image/jpeg"
]
2. I checked the generated Content-Type, and it meets expectations. When the corresponding extension does not exist, it returns null. In this case, fallback handling is needed.
PHP
Log::info(
$return['asset_key'],
[
$return['asset_key'],
$this->detector->detectMimeTypeFromPath($fullPath) ?? mime_content_type($fullPath),
]
);
