I’m looking for solution to add css/js files to document node when special element is added as element of a page.
Maybe anybody know good solution for it instead of flowquery by nodetype on documentnode
Is there any plugin/extension that helps with it?
FlowQuery the for the existence of a specific nodeType or mixin is not that bad. It is the price to pay for beeing able to render each part of the fusion tree. Everything else would require communication between distant branches of fusion.
Also make sure that you add an @cache to the fragment as otherwise the header is cached with the document and will not be updated once you add the contents of your page.
I beg to differ
It might not be a (big) performance issue but IMO we should built a mental barrier between node types and the components that are rendered on your site.
I assume included CSS/JS is about the latter and might not always be about the former so I think it should be possible to register the required assets from the rendering part (i.e. the component) in order to load them dynamically.
Maybe something like this could work:
1. Render a placeholder into the page source code:
This is obviously just a rough idea and I might miss something.
And apart from that all, the whole idea of loading dynamic assets might be a dangerous path that leads to worse performance in the end (e.g. the overhead of requesting multiple assets vs one minified blob…)
While i generally agree that this is not what nodeTypes are for, i think using mixins as markers for such cases is okish aswell and quite easy to understand and debug.
For a cleaner approach how about adding those js- or css-requirements as special data-attributes and later use an http-component to render them to the header. That could even be extracted into a dedicated package. Using a special prototype to get this informations always comes with the danger of beeing cached wrong.
@bwaidelich@mficzel Thank You very much for discussion and solution.
I was “out of Neos” a bit and couldn’t view/test what You’ve provided. I’ll try i next few days.
@mficzel Last weekend I’ve tested it localy on ddev and it works like a charm. Thank You very much. For real life will probably have to wait. Maybe even not so long. I think I’ll try to use it next time when our frontend colleagues will demand external css or js.