Cache not busted when using browserclass tokens in body field

Created on 11 March 2024, 7 months ago
Updated 14 April 2024, 6 months ago

Hello,

How to solve the caching problem? After using a token to obtain device information, the information accessed again on all devices is the same. When clearing the cache, new device information is obtained.

access in Windows

1.[browserclass:browser]
2.[browserclass:platform]
3.[browserclass:hook-classes]
4.[browserclass:device]
5.[browserclass:browser-classes]
1.chrome chrome122
2.win
3.
4.desktop
5.chrome chrome122 win desktop

There is no change in accessing using mobile devices.
However, when I clear the cache, it becomes the following information.

1.chrome chrome99
2.android
3.
4.mobile
5.chrome chrome99 android mobile
🐛 Bug report
Status

Active

Version

1.0

Component

Miscellaneous

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @msn5158
  • leymannx Berlin

    Where did you place the token exactly? Where is the output getting printed exactly?

  • Status changed to Postponed: needs info 7 months ago
  • leymannx Berlin

    Please provide at least some steps to reproduce this issue, so we are able find the problem causing it.

  • Steps To Reproduce:
    1.Add content > Article
    2.Place the following token to Body, Text format choose Full HTML, Save the Article.

    1.[browserclass:browser]
    2.[browserclass:platform]
    3.[browserclass:hook-classes]
    4.[browserclass:device]
    5.[browserclass:browser-classes]

    3.Flush all caches.
    4.Access the node article by PC device first. You can see the token replacement information.

    1.chrome chrome114
    2.win
    3.
    4.desktop
    5.chrome chrome114 win desktop

    5.Access the node article by Mobile device now. You can see the token replacement are the same of PC device.
    Continue
    6.Flush all caches again but please not in the current node article page.
    7.Access the node article by Mobile device first. You can see the token replacement information.

    1.chrome chrome99
    2.android
    3.
    4.mobile
    5.chrome chrome99 android mobile

    6.Access the node article by PC device now. You can see the token replacement are the same of Mobile device.

  • Note:

    Either log out all to access through PC and Mobile devices or log in all.
    But not log in to access through PC devices, and log out to access through Mobile devices.

  • Status changed to Active 7 months ago
  • leymannx Berlin

    Ah, I see. Thank you very much for the details. I will check.

    One last thing: Are the classes added correctly to the page's body tag?

  • I only tested tokens and did not test classes, And I don't know how to use classes.

    I want to use this module to obtain information from the PC and Mobile devices, and then decide to display different page layouts.

    This issue is not only appear to the Body field of the content, such as blocks and views use these tokens, also the same problem.

  • Is this issue related to classes?

    Will this caching issue be resolved if adding classes correctly to the page's body tag?

    Thank you

  • leymannx Berlin

    Like the description page says this module should give you some CSS classes on the body tag. Which happens via JavaScript to prevent any caching issues. It's also not very let's say sustainable to bust the cache on every different browser. Because there are millions.

    <body class="... chrome chrome11 mac desktop">
    ...
    </body>

    In CSS you then can use it to style things differently:

    body.chrome.mac p {
      font-size: 11px;
    }

    I think with tokens the problem is that a custom cache tag has never been implemented. And as said already it's probably not the wisest move to bust the page cache on every different browser which comes to your site.

    But I need to check. For the time being, yes, it's much better you rely on the body tag classes added via JavaScript.

  • I see now, as long as the module is installed, it automatically adds attributes to the body tag.

    I test the following CSS, they each work normally, so they are working according to the design, but the tokens not, just like the question I mentioned.

    body.chrome.win p {
      font-size: 30px;
      color:red;
    }
    body.chrome.android p {
      font-size: 11px;
      color:blue;
    }
  • Hello,

    Can this problem be solved?

    I suggested in the core issue Set up two caching systems for mobile and computer devices Closed: works as designed that desktop browser caching and mobile browser caching be separated to solve two different client caching problems, but it was not adopted.

    The another module ( mobile_detect ) also has the same problem.

    Thank you

  • leymannx Berlin

    Can you give a little bit more context? Like why is the body class not suitable for your needs? What do you do exactly with these tokens?

  • Yes. I used a table to layout the content, but it was displayed too large on the mobile screen if there were too many

  • leymannx Berlin

    Can you print an obfuscated content of that field's content like you use it now with the tokens?

    The browserclass module is actually just for adding a class and then style things accordingly.

    The token seems to vary per user given the module description. Means all unauth users will get the first hit which then is cached.

  • I am currently using classes to control the display, although the effect is not very good, but hope one day it can solve the problem. Or leave some suggestions to the core issue to solve two types of device caching problems.

    Perhaps the core issue is not user-friendly enough, or it does not support separate caching of two devices. I use PHP to obtain device information, but there is the same problem. It can only display the first hit cache, and to make it effective, internal page caching must be disabled, but this greatly reduces performance.

  • leymannx Berlin

    Yeah best would be to leave it to JS, which the body class does. Tokens is PHP, I'm not even sure you can send cache tags along a token, but since user tokens do there must be something with a custom browser tag as well.

    Best is you circumvent PHP (server code layer) here and do something with JS and CSS (browser display layer).

Production build 0.71.5 2024