Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background image disappears with Grav's caching turned on #2

Closed
mikolajgolunski opened this issue Nov 26, 2020 · 4 comments
Closed

Comments

@mikolajgolunski
Copy link

Grav 1.7.0 rc. 17
With the Grav's caching turned off background images work fine. When turning the caching on (the regular caching from the admin panel) the background image disappears after being cached (it is visible the first time loading page but disapears after the reload). It appears again only after clearing the cache (until reload when it disappears again) or after turning off the caching completely.
I've found that proper class is preserved but style definition gets deleted from the head of the page.
Didn't try it on stable release of Grav nor with any caching plugins yet.

@OliverO2
Copy link
Owner

Thanks for this report. So far, the plugin has been tested on the current release series only (Grav 1.6).

The plugin uses Grav's asset manager, more specifically its function addInlineCss to insert CSS into the page. What you are seeing could be a problem in Grav's interaction between its AssetManager and cache. A quick search revealed one issue that might provide some hints: getgrav/grav#2445

Would it help in your case if you follow the advice in getgrav/grav#2445 (comment) and set

never_cache_twig: true

in the page's frontmatter?

@mikolajgolunski
Copy link
Author

Yeah, with disabling Twig caching for the page the background image works fine. Thanks 👍

@OliverO2
Copy link
Owner

OliverO2 commented Mar 1, 2021

The issue appears when background images are used inside a page's content (as opposed to a template). This use case has not been described in the plugin's documentation.

Version 3.0.0 now contains a section on how to use a background image in the page's content, describing the never_cache_twig requirement in this case.

@OliverO2 OliverO2 closed this as completed Mar 1, 2021
@OliverO2
Copy link
Owner

OliverO2 commented Mar 8, 2021

Update: The problem appears to be caused by Grav failing to correctly deal with Twig caching on modular pages (this is getgrav/grav#1934). In these scenarios, Grav caches a modular page's HTML content, but forgets to cache the CSS (or JS) code generated along with the output by Twig functions.

So whether background images are specified in templates or in pages does not matter. What matters is whether a background image appears in a modular page.

This has been documented along with a workaround in version 3.0.2 of this plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants