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

Ability to "reset" cache of rendered files automatically in Twig #90

Closed
weaverryan opened this issue Apr 22, 2020 · 2 comments · Fixed by #115 · May be fixed by #91
Closed

Ability to "reset" cache of rendered files automatically in Twig #90

weaverryan opened this issue Apr 22, 2020 · 2 comments · Fixed by #115 · May be fixed by #91

Comments

@weaverryan
Copy link
Member

Related #87

When you encore_entry_link_tags() or encore_entry_script_tags() tags, the bundle "remembers" which CSS and JS files have been rendered and avoids rendering them again. This is by design: it allows you to render multiple "entries" on the same page and avoid link/script tags for the same CSS & JS files (due to code splitting).

But, this has some nasty side effects. One practical one is sending emails and using these functions to import your CSS. If you have Messenger installed, each Email is technically rendered twice - and the second (real) email will contain no CSS link tags. The problem is probably worse when sending emails through the queue - as I think once a worker has sent one email, the rest won't contain CSS link tags.

The best solution would be to reset "automatically" the cache after a "main" Twig rendering (e.g. a call to$twig->render()) but no such concept currently exists in Twig.

A more immediate solution may be to allow users to "opt out" of the cache via some argument to encore_entry_link_tags().

Warxcell added a commit to Warxcell/webpack-encore-bundle that referenced this issue Mar 19, 2021
Warxcell added a commit to Warxcell/webpack-encore-bundle that referenced this issue Mar 19, 2021
weaverryan added a commit that referenced this issue Feb 10, 2022
This PR was merged into the main branch.

Discussion
----------

Reset assets on FINISH_REQUEST.

Fixes #90, #94

Commits
-------

029b01b Reset caches on FINISH_REQUEST. Fixes #90, #94
@bobvandevijver
Copy link

@weaverryan are you sure the linked MR fixes this for the messenger case as well?

The FINISH_REQUEST event occurs when a response was generated for a request.

@weaverryan
Copy link
Member Author

You're right - it didn't address the Messenger side of things. However, I think (but I am doing some guessing) that this will be handled via the new reset_on_message config: https://symfony.com/blog/new-in-symfony-5-4-messenger-improvements#reset-container-services-between-messages

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