- Issue created by @bburg
I see that in π Block content cache 'max-age' RTBC caching was added to the block, which is great, but the cache contexts for "url", and "url.query_args" seems to lead to an excessive amount of variability in the render cache. I'm using Pantheon, which uses Redis, and even on an "Elite" plan, I am limited to 920MB of cache memory. This is a fairly large site, with lots of pages, and the gtranslate block appears on every one. This has lead to over 13000 variations for the block:
entity_view:block:{my theme}_gtranslate: 13526 (url)
This is out of over 52,000 items in the render cache. We are dealing with performance issues on the site, and my concern is that this is occupying an unnecessary amount of memory for the cache variations, where likely one 1 is needed.
I understand that a few examples of code appears in the block rendering similar to this:
$orig_url = Html::escape(\Drupal::request()->getBasePath() . \Drupal::request()->getPathInfo());
$orig_domain = Html::escape(\Drupal::request()->getHost());
Later in the code, there are several examples where some javascript is generated via this function:
private function get_script_code($src, $orig_url, $orig_domain) {
//jQuery does not preserve script attributes, so instead of the line below we have to do tricks
//$script_code = '<script src="'.$src.'" data-gt-orig-url="'.$orig_url.'" data-gt-orig-domain="'.$orig_domain.'" defer></script>';
$script_code = '<script>';
$script_code .= "(function(){var js = document.createElement('script');";
$script_code .= "js.setAttribute('src', '$src');";
$script_code .= "js.setAttribute('data-gt-orig-url', '$orig_url');";
$script_code .= "js.setAttribute('data-gt-orig-domain', '$orig_domain');";
$script_code .= "document.body.appendChild(js);})();";
$script_code .= '</script>';
return $script_code;
}
Perhaps I'm missing something, but if the purpose of this code is pass the current URL as attributes to jquery, then why can't we just grab that on the front-end with "window.location"?
Active
3.0
Code