Closed filippomasoni closed 3 years ago
Hi, @filippomasoni I finally got to work on the issue, but it seems I can't reproduce it. No matter if I clear the cache or reload the page multiple times, it always loads both CSS and JS
Do you have at the bottom of your base template (before </body>
) this? Because the init()
JS is placed there (in the bottom
block)
{{ assets.js('bottom')|raw }}
Here's my page config:
And global caching config:
Hi, sorry for the delay, I'm now getting back to work on web dev after I finished my last project.
I have {% block bottom %} {{ assets.js('bottom')|raw }} {% endblock %}
before
so that's ok.
On a page level I have the following:
I had to enable Never cache twig on the modular page containing the gallery to make it work.
On global caching I have everything the same except: Clear image cache by default, enabled because that's the default in Grav. Not sure if that's the issue.
I'm going to update some of my sites and star working on something new in the next few days so I'll have more time for testing. I'll let you know if I find something new.
Hmm... I suspect this might be related to how modular pages are cached. I tested on a non-modular page 🤔 I recall some kind of discussion related to modular page caching, will have to search for it
Can reproduce in modular page
Asked some questions and searched a bit and found this old comment from the Grav developer himself and it kinda makes sense.
Just checked and never_cache_twig: true
on that specific module page does help.
So basically what happens with modular, as I understand it, all modules are merged and cached as one modular page and next time it renders, Twig extension which renders Photoswipe is never called. Disabling Twig cache makes it render after the content is cached and that makes assets render.
Sorry, but it's a Won't fix from where I stand 🙂 Hope you understand and enjoy my plugin otherwise 🙂
BTW, you could move {{ photoswipe('your-element-id', 'a') }}
from the module template to the main modular page template. Just tested and that works, but I see the issue here if you want to use multiple galleries on multiple modules on same modular - you'd need different element IDs for each of them
Thank you for actually putting the time in and researching the problem.
I actually find that old comment from the Grav dev very important as it explains the best way to handle things like this maintaining maximum cache performance possible. I'm glad that's exactly what I previously did without knowing the details, I just did some trial and error.
I'm glad we now understand why it happens and hopefully will be helpful to others.
I do actually want to have multiple galleries on my modular page and I have my gallery.html.twig template including photoswipe and giving it a dynamic ID based on the page folder name. I've done the same before with another gallery plugin.
At this point, I think the best solution for people that want to use photoswipe on modular pages, is to have a default never_cache_twig: true
on the blueprint of the template. You could suggest that on the documentation. I'm gonna set that up now, I was just waiting if there was a different fix.
Thank you again and have a great day
It works perfectly with cache disables or with “never cache twig” enabled on the gallery modular page, otherwise at the second refresh photoswipe css and js are not loaded anymore.
I’m on the latest stable Grav version with admin and other plugins. I’m including css and js from the base theme like this:
I tried on a different Grav install (v1.7.10) as well and it’s doing the same.