Drupal 8 version of #2558473: Some assets don't have correct CDN file path.
When using far-future expiration, linked in CSS files with relative paths result in 404 not found errors when requested by the browser.
Depending on the maintainers' thoughts on this, it could just be "the way it is"/works as designed, or a bug. Basically the issue goes away if you turn on CSS aggregation, because those URLs become root-relative, and per #2745109: Files referenced in CSS aggregates should not have CDN URLs: already root-relative, and they cannot be safely made forever cacheable anyway that's the intended behavior.
Without CSS aggregation turned on, the requests get made to a URL with a security token in them, but only because those requests are made relative to the path of the CSS file referencing them, which are subject to far-future expiration.
Comment | File | Size | Author |
---|---|---|---|
#15 | 2827638-14.patch | 632 bytes | Wim Leers |
#13 | Screen Shot 2016-11-17 at 10.45.25.png | 33.98 KB | Wim Leers |
#12 | interdiff.txt | 5.9 KB | Wim Leers |
#12 | 2827638-12.patch | 2.82 KB | Wim Leers |
#5 | 2827638-farfuture-css-5.patch | 3.45 KB | bradjones1 |
Comments
Comment #2
Wim Leers#2745109: Files referenced in CSS aggregates should not have CDN URLs: already root-relative, and they cannot be safely made forever cacheable anyway addressed the handling of files referenced by CSS files. It has test coverage specifically for the case when Far Future expiration is enabled. And hence I don't see how this is possible.
So it would seem you're on a dev version older than beta 1. Please upgrade.
If the problem then still persists, please provide steps to reproduce.
Comment #3
Wim LeersOh wait, that screenshot proves you don't have CSS aggregation enabled. That means the CDN module is unable to rewrite file URLs in CSS files. Hence there's no way it can possibly work.
This leaves me with a few options:
None of these is ideal.
What do you think?
Comment #4
bradjones1Putting the onus on the developer is fine, in part, but we should probably provide some UI or README notices (or both) to keep others from having to find this issue. Auto-disabling seems like overkill, especially if you've got some temporary reason to try and run incompatible settings for testing, or something.
Attached is a patch that fires a notice if the user has the UI configuration management permission and the condition outlined here is true.
Comment #5
bradjones1Fixed a missing docblock.
Comment #8
bradjones1Ah, test services need a different mock now that the service has an additional parameter.
Comment #9
Wim LeersSo you prefer option 2, because option 3 seems overkill and option 1 is what got you to report this issue. That's fair.
I'm not yet entirely convinced myself that this all makes sense. Does this feel like sensible behavior to you?
Comment #10
bradjones1What are you asking about, the problem condition or the solution?
If you're referring to the notification to the admin, I think it might help save some frustration on the part of less-technically minded site admins. CDN works with almost zero config out of the box, but site-builders might not read every line of the README.
In the case of the initial problem, I'll defer to you... I would imagine there's a solution out there to somehow normalize the relative URLs since we know the new structure, but I'm unlikely to justify spending time "fixing" that personally, since production sites pretty much always run with aggregation turned on.
Comment #11
Wim LeersI was referring to the solution: it's less than ideal, it's pretty "WTF"-inducing.
Related: #2827998: Add a new default option to the CDN UI: "all files except CSS+JS", and make this the new default of the CDN module, include upgrade path will change the default, so that CSS and JS files are no longer being served from a CDN anymore. That would reduce the chances of running into this problem.
Thanks for sharing your thinking about this! It's always better to think things through with multiple people.
I'm in favor of adding this. We must explain WTFs, even if they are rare to run into.
This logic needs to move to a helper method on
HtmlResponseSubscriber
. TheCdnSettings
class must not generate messages, it's only purpose is parsing/interpreting thecdn.settings
config.$this->cdnSettings->isEnabled()
.Comment #12
Wim LeersThis is basically what I was asking for. Still needs cleaning up, but this is the structure we want.
While working on this, this made me realize that this is significantly increasing the overhead of the CDN module. It's more than twice as expensive as
addDnsPrefetchLinkHeaders()
.Comment #13
Wim LeersThis is what that looks like BTW.
Comment #14
Wim LeersHere's a completely different approach: it detects if
settings.php
(orsettings.local.php
) disable CSS aggregation, and in that case, it will just not alter any CSS file URLs.No need for warnings; everything continues to work just fine.
Thoughts?
Comment #15
Wim LeersForgot the patch.
Comment #16
Wim LeersSo this would not address the case of developers intentionally disabling CSS aggregation for a site. It's a bad practice to disable it anyway. And in that case, they should arguably be smart enough: if they have reasons to disable CSS aggregation, they should also be smart enough to update the CDN module's settings.
Finally, every developer should know to use
settings.local.php
, they should not manually disable it in the UI.Comment #17
Wim LeersI think the patch in #15 strikes a nice balance between pragmatism and strictness. It just silently ignores CSS file URLs when CSS aggregation is off. It doesn't ever get in your way. It doesn't require you to keep two pieces of configuration in sync. It doesn't require us to start altering other forms with additional validation logic and messages.
Combined with the fact that the CDN module will by default not serve CSS files from a CDN (since #2827998: Add a new default option to the CDN UI: "all files except CSS+JS", and make this the new default of the CDN module, include upgrade path), I think this adequately addresses the majority use case. We can add a warning message in the future if the need arises. But I'd rather not, because it slows things down and gets in the way.
Comment #18
Wim LeersComment #19
Wim LeersComment #20
anavarreLooks like a very good compromise. Intentionally disabling CSS aggregation for a site means you either have issues to fix that should get you worried or you know what you're doing and you can find workarounds for the CDN module.
Also agreed that
settings.local.php
is the way to go for sustainable dev mode rather than clicking around. And if you can deal withsites.php
, surely you can deal withsettings.local.php
anyway.#17 is a compelling reason to go with the patch in #15 IMHO. Also, with #2827998: Add a new default option to the CDN UI: "all files except CSS+JS", and make this the new default of the CDN module, include upgrade path now committed, the need should erode as time goes by.
Comment #21
Wim LeersExcellent, thanks for sharing your perspective, @anavarre!
Comment #23
Wim Leers