0

I've made a small change on a view (added a new class) and some related changes in the CSS files of the theme.
Since the config change (HTML output) is immediately in effect, I need the browser to be made aware that it has to re-download the theme CSS files.

However, using the "Clear all caches" button on the Performance page of the Drupal admin doesn't seem to have any effect in that regard, and the browser still shows the old (locally cached) CSS, unless I hit Ctrl+F5. (But I can't ask all my visitors to do that.)

Here's an example of the HTML output when aggregation is ON:

<link rel="stylesheet" media="all" href="/sites/default/files/css/css_4XTr0kQoY87Py6qdkph9UELdhubJ3OyJba-NTQiautY.css?delta=0&amp;language=fr&amp;theme=mytheme&amp;include=eJxNyEEKgDAMRNELBXOmqIMUGiOd1lJPLxQXbh6fz8EK19UIqXEFdfr1bztIO0DZokDPKG45PZA7oVOni8feMl5WAyCI" />
<link rel="stylesheet" media="all" href="/sites/default/files/css/css_RRKbpxmmUbIPWnmPINgX_B4xj3dmPgTl24PPYLoDZpc.css?delta=1&amp;language=fr&amp;theme=mytheme&amp;include=eJxNyEEKgDAMRNELBXOmqIMUGiOd1lJPLxQXbh6fz8EK19UIqXEFdfr1bztIO0DZokDPKG45PZA7oVOni8feMl5WAyCI" />

I would expect some of those parameters (or the file names) to change when clicking Clear all caches, but they don't.

Here is what I tried:

  1. On the Performance page:
  • "Clear all caches".
  • Then refresh the page source in Firefox or Chrome (Ctrl+F5).

=> Exact same output

  1. On the Performance page:
  • Disable aggregation, save;
  • Clear all caches;
  • Enable aggregation, save;
  • Clear all caches;
  • Then refresh the page source in Firefox or Chrome (Ctrl+F5).

=> Exact same output

For now my "solution" was to disable CSS aggregation, so the file names are entirely different and therefore the browser will download them again, but this is hardly ideal.

Is there something I am missing?

4
  • Drupal core does what you are looking for by default, so something in your system is introducing the bug you are seeing. Try a different theme and see if that fixes the problem, and you'll know the issue is in your theme. Otherwise, start disabling modules until the desired function is seen, to determine which module is introducing this bug.
    – Jaypan
    Feb 23 at 17:25
  • Do you have a reverse proxy or other caching solution sitting in front of the site? Varnish, Cloudflare, etc. if so disable it to test that the standard functionality Jaypan mentioned is working. Then tweak your cache settings for your desired outcome
    – Clive
    Feb 23 at 17:37
  • @Jaypan OK, good to know that it's not supposed to behave like that. I'll see what I can do to find the cause.
    – s427
    Feb 23 at 17:46
  • @Clive not that I'm aware of (it's a shared hosting)
    – s427
    Feb 23 at 17:48

1 Answer 1

2

After changes you also have to increase the version number in your libraries.yml file to generate new aggregated CSS files.

4
  • 2
    Worth mentioning that this is only true if you actually have the version explicitly set in your libraries’ yml files. If you don’t manually version your libraries, they use the system wide cache buster
    – Clive
    Feb 23 at 18:58
  • Ah, that's a good point, thanks.
    – s427
    Feb 24 at 1:23
  • @Clive If I have a project that currently uses version numbers in libraries.yml, can I just delete all those and get reliable cache busting when I push changes from now on? Apr 4 at 14:49
  • 1
    In theory yes @LannyHeidbreder. YMMV for a particular install, but generally speaking removing version (then rebuilding caches) will get your libraries to fall in line with the system aggregation
    – Clive
    Apr 4 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.