How to add Custom Javascript for Custom Page?

Hi,
how to add custom javascript just for a custom created route / page?

The documentation just show how to add it globally:

Add custom Javascript - Shopware Developer

~Marc

It depends on how you register your plugin. You can bind your plugin to a Dom element.

But the code is still loaded on any page even when not used on that page

That’s the magic of web pack :laughing:

With your restriction every url would have its own js and css file.

Not sure, but I think I’ve read something like splitted assets in Shopware 6.5.

HTML, CSS, und JavaSript Inhalte als Erlebniswelt-Element und somit individuell einsetzbar
je Seite/Kategorie/Produkt/…

Auch interessant um Global css/js zu hinterlegen.

Nur zur Ergänzung

Wirklich sehr hilfreiche und praktische Hilfsmittel,
ich sage nochmals danke an die Entwickler das sie uns dieses zentrale Mittel zur VerfĂĽgung gaben.

1 Like

Vielen Dank fĂĽr die Antworten
und ich werde alle Vorschläge testen!


Thank you very much for the answers
And I will test all the suggestions!

YES!

But atm only for the core and not plugins, as far as I understood