We have a site in Drupal 8 where a few pages are being served using Drupal 8 Controllers. However, when the page is navigated using the browser backward and forward buttons, the browser (Chrome in this example) is serving cached variables. The Javascript is seeing the same value for a variable in drupalSettings, which should have been changed if the page was reloaded from the Drupal Server.

I found this tutorial which says adding the response header cache-control: no-store might help resolve this issue. How do we return such a response header in Drupal 8?

  • Another way would be to ajaxify it. Maybe expose a second route which returns a JSON response (which is uncached by default), and then in your JS check that route and use the response to do whatever you need to do. Similar to what's been done in this very small module: drupal.org/project/user_online_status – leymannx Dec 16 '18 at 22:07

Browse other questions tagged or ask your own question.