I tried setting headers:dnt and also max-age, but it has no effect. The #attached code is always cached.
Example snippet (change the text to see that the cache is not refreshing):
function mymodule_page_attachments(array &$page) {
$dnt = (!empty($_SERVER['HTTP_DNT'])) ? [] : ['headers:dnt'];
$page['#cache']['contexts'] = Cache::mergeContexts(isset($page['#cache']['contexts']) ? $page['#cache']['contexts'] : [], $dnt);
$page['#cache']['tags'] = Cache::mergeTags(isset($page['#cache']['tags']) ? $page['#cache']['tags'] : [], $config->getCacheTags());
$page['#cache']['max-age'] = 0;
$script = 'alert('This is a test.');';
$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#value' => $script,
],
'mymodule_script',
];
}
How can I make the script dependend on a lot of rules? Best would be no cache at all.
Closed: duplicate
8.5 β°οΈ
It affects performance. It is often combined with the Needs profiling tag.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.