Open bnomei opened 2 days ago
Thank you for the feedback! I didn't even consider the pages cache. I will add the warning right away and implement a fix tomorrow
Chiming in here quickly: Calling $kirby->user()
will not completely disable the pages cache, but it will trigger the automatic cacheability detection. For the plugin this should mean:
A note on Bruno's proposed solution: Maybe it could be implemented so that the route either returns the rendered admin bar snippet for the user (thus avoiding having to put the HTML into all responses, even for visitors) or an empty response with 204
status code. The frontend part can then just either inject that HTML into the page as returned from the backend or (if 204
response) do nothing. This should be doable without JS libraries.
This should be doable without JS libraries.
This was my plan. To keep it as lean as possible. However an additional request means that the page might have some unpleasant jumps since we do not know in advance whether the admin bar should be rendered or not. The current solution is also very clean in a way that guests won't even know it's there at all - which I quite like. I will do some testing tomorrow and see if there's a decent compromise for this.
Absolutely, that was also a thought I had. Maybe it could be an option so those who don't use the pages cache, Staticache or a CDN don't get the added JS and fetch request but the snippet directly.
We have a plugin that inserts a snippet into the HTML in a page.render:after
hook. But only if the user is logged in and without interfering with the Kirby cache:
https://github.com/junohamburg/kirby-reload-on-save?tab=readme-ov-file#setup
This might work for your plugin as well.
Thanks a lot for the recommendation! That is a really good solution. I will implement it later today.
Kirby cache
This should only be true for the basic "Pages Cache" via PHP but not apply to the pages cache with the additional Staticache plugin. As the staticache will have the server render the HTML file directly without booting Kirby at all.
But non the the less a neat solution to use page.render:after
👏 .
Thanks everyone for the feedback! I changed the implementation to use the hook instead of the snippet and released it as a 2.0 to avoid breaking people's current deployments.
love your plugin. way nicer than my hacks.
Doing a check for user like that will disable the pages cache for said page. Thus your plugin is currently incompatible with the pages cache and you might want to put a warning in the readme.
https://github.com/Pechente/kirby-admin-bar/blob/e01fccf2cc7ed535ff36aab9ac417a8da1c40620/snippets/admin-bar.php#L5
a solution would be to instead of using a check in PHP first query an endpoint and use js to show the area. in your case hydrate with user information like image and name as well. like this with alpine js
snippet
route