Problem/Motivation
For years now I've encountered rare, random issues where stylesheets are seemingly being loaded with incorrect encoding. This might occur once every few weeks, and only for one page view. None of the usual suspects really apply here like lack of <meta charset="utf-8"> in the document, etc...
That led me to start grasping at straws and I did an AI query on this which led to the tool citing https://issues.chromium.org/issues/40302205 (disk cache nondeterminism).
I looked up the implementation of Drupal's asset aggregator controller and sure enough, the Content-Type header lacks encoding.
Should the Content-Type response header be updated to text/{css|javascript}; charset=utf8 for these resources? What about the .htaccess file for such resources?
Steps to reproduce
Add a
.some-selector {
content: '“';
}
selector, then notice that rarely, randomly the character is printed as “. Do a hard refresh; note that the character is printed properly (interpreted as utf-8).
Proposed resolution
Perhaps add an explicit charset to the CSS and JS Content-Type headers?
Remaining tasks
TBD
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
TBD
Comments
Comment #2
longwaveCssOptimizer::loadFile()actually ensures all aggregated CSS is UTF-8 by converting non-UTF-8 charsets automatically and::clean()strips other charset declarations. Therefore if this fixes an edge case bug it seems like a good idea to add it as the charset will always be UTF-8 as far as I can tell.It's not clear if the same problem exists for JavaScript files or if they are always treated as UTF-8, but I don't see that it would hurt to add the charset to the Content-Type header there either.