# How to add Custom Javascript for Custom Page?

**URL:** https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645
**Category:** Shopware 6 (English)
**Created:** [21. Februar 2023 um 13:07 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645 "2023-02-21T13:07:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![daslicht](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@daslicht](https://forum.shopware.com/u/daslicht)
#### Post date: [21. Februar 2023 um 13:07 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/1 "2023-02-21T13:07:44Z")

</div>

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 Documentation](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-javascript)

~Marc

---

<div class="post-metadata">

### Author: ![abdullah](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@abdullah](https://forum.shopware.com/u/abdullah)
#### Post date: [21. Februar 2023 um 18:03 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/2 "2023-02-21T18:03:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![daslicht](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@daslicht](https://forum.shopware.com/u/daslicht)
#### Post date: [22. Februar 2023 um 07:50 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/3 "2023-02-22T07:50:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)
#### Post date: [22. Februar 2023 um 08:06 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/4 "2023-02-22T08:06:21Z")

</div>

That’s the magic of web pack 😆

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.

---

<div class="post-metadata">

### Author: ![Thorsten-A](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@Thorsten-A](https://forum.shopware.com/u/Thorsten-A)
#### Post date: [22. Februar 2023 um 12:26 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/5 "2023-02-22T12:26:19Z")

</div>

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

> **[HTML Erlebniswelten Element mit Twig Compiler](https://store.shopware.com/moorl29420842994f/html-erlebniswelten-element-mit-twig-compiler.html)**
>
> Du möchtest bereits fertige HTML-, JavaScript-, und CSS-Inhalte in den Erlebniswelten nutzen, aber der Code wird durch die normalerweise verwendeten…

Auch interessant um Global css/js zu hinterlegen.

> **[Custom JavaScript/CSS Manager für Shopware 6](https://store.shopware.com/dne5719820551438f/custom-javascript/css-manager-fuer-shopware-6.html)**
>
> Fügt dem Backend einen Container Manager für eigenes JavaScript/CSS/SCSS hinzu. Das Plugin bietet die folgenden Features: Anlegen von beliebig…

Nur zur Ergänzung

> **[Foundation | Basis Version](https://store.shopware.com/moorl50852475974f/foundation-basis-version.html)**
>
> Foundation wird von folgenden Plugins verwendet Sofern nicht anders angegeben, wird moori Foundation in folgenden Plugins verwendet Plugins von…

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

---

<div class="post-metadata">

### Author: ![daslicht](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@daslicht](https://forum.shopware.com/u/daslicht)
#### Post date: [22. Februar 2023 um 17:02 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/6 "2023-02-22T17:02:12Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![daslicht](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@daslicht](https://forum.shopware.com/u/daslicht)
#### Post date: [22. Februar 2023 um 18:15 UTC](https://forum.shopware.com/t/how-to-add-custom-javascript-for-custom-page/98645/7 "2023-02-22T18:15:04Z")

</div>

> [@Max\_Shop](#):
>
> Not sure, but I think I’ve read something like splitted assets in Shopware 6.5.

YES!

 ![Screenshot 2023-02-22 at 19.14.19](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/5/f/5ffd218b10a8b865001b2725c5db5ed50ef9ca47.jpeg)

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