Problem/Motivation
While you are developing a custom module, and integrating with anything client cached, you won't find your new elements (e.g. Contextual links). As a developer, your first thought would be "clear Drupal cache", but that won't solve it. Even knowing the excellent client-side caching solution in D8, I lost some time debugging while trying to integrate a custom module with Contextual Links (i.e. the new contextual links weren't showing up).
In the case of contextual links, window.sessionStorage is used, which means that opening a new tab is enough to get rid of the client-side cache. But this won't be obvious for a D8 newcomer.
Client-side caching works as designed, but there is no way of disabling it while in development. There should be, to have a better DX.
Proposed resolution
Introducing a drupalSettings.disableClientSideCaching boolean flag, that can be enabled from settings.local.php (setting) /development.services.yml (container parameter). Any Drupal module doing client-side caching could then opt in to check whether that value exists and if it's set to TRUE, it would disable all client-side caching.
Remaining tasks
Discuss possible solutions.
Patch.
Review.
Commit.
User interface changes
None.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | disable_client_side_caching_flag-2395453-3.patch | 6.06 KB | wim leers |
Comments
Comment #1
dawehner.
Comment #2
wim leersComment #3
wim leersAnd patch.
We don't want to uniformly forbid the use of sessionStorage/localStorage; it's often also used to persist state. This is not the same as client-side caching of data. Each piece of JS can choose how to handle the
drupalSettings.clientSideCachingsetting.Assigning to nod_ for review.
Comment #4
nod_That's not a reliable way to get the keys,
is the "spec" way of doing it.
More generally I don't like the fact that we have an arbitrary variable used all over the place and especially expect contrib to know about it and use it properly. If we're serious about this we should abstract local/sessionStorage in a — very simple — Drupal.storage object (that way we could simplify some JSON.stringify/JSON.parse too). That way contrib don't have to deal with all this.
All in all I agree there is a problem, I agree we should have a solution, I just don't like adding killswitches and the java-ish-named method
deleteFromClientSideCacheByPrefix. There is such a thing as too explicit, if we're still going this way a name such asclearStoragePrefixwould probably be better.Comment #5
wim leersI considered this too, but that's not an option either. Look at e.g. Quick Edit's JS: it needs to write to localStorage/sessionStorage, but it can empty it at the beginning of every request. Contrast that with e.g. Contextual's JS, which can just return early.
Different designs, different needs, there's no one-size-fits-it-all solution.
Comment #8
tim.plunkettThis is extremely important for DX, IMO
Comment #9
wim leersBumping to then. Can you clarify why you find this so important? Did you lose much time over this?
Comment #10
tim.plunkettInfinite amount of
drush cr-ing will not help you on this.What happens to help is rage-force-quitting your browser and then trying again later!
This needs a $settings flag in settings.local.php just like the ones to disable CSS/JS aggregation and render cache.
Comment #24
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #26
smustgrave commentedThink this can be closed now that we have the Development Setting in core. If I'm wrong please re-open.