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.

Comments

dawehner’s picture

wim leers’s picture

Title: Client caching is a hidden feature that can boost your site, but reduce DX » Client-side caching is a hidden feature that can boost your site, but reduce DX
Issue summary: View changes
wim leers’s picture

Title: Client-side caching is a hidden feature that can boost your site, but reduce DX » Allow client-side caching to be disabled while developing
Assigned: Unassigned » nod_
Status: Active » Needs review
StatusFileSize
new6.06 KB

And 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.clientSideCaching setting.

Assigning to nod_ for review.

nod_’s picture

Status: Needs review » Needs work
+++ b/core/misc/drupal.js
@@ -428,4 +428,20 @@ if (window.jQuery) {
+    Object.keys(storage).forEach(function (key) {
+      if (key.substring(0, prefix.length) === prefix) {
+        storage.removeItem(key);
+      }
+    });

That's not a reliable way to get the keys,

for (var i = 0; i < storage.length; i += 1) {
  var key = storage.key(i);
  // the rest
}

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 as clearStoragePrefix would probably be better.

wim leers’s picture

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.

I 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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Version: 8.2.x-dev » 8.3.x-dev
Assigned: nod_ » Unassigned

This is extremely important for DX, IMO

wim leers’s picture

Priority: Normal » Major

Bumping to major then. Can you clarify why you find this so important? Did you lose much time over this?

tim.plunkett’s picture

Infinite 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: -JavaScript +JavaScript, +stale-issue-cleanup

Thank 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!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Think this can be closed now that we have the Development Setting in core. If I'm wrong please re-open.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.