1

Im trying to add custom JS in my new theme. I managed to add custom css in default_head_blocks.xml Like this:

<css src="css/customtheme.css" />
<css src="css/styles-m.css" />
<css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
<css src="css/print.css" media="print" />

Now i tried to do the same with javascript:

<script src="js/javascript.js" />

To test it i added this code in js/javascript.js:

alert('test!');

But sadly nothing. What is the corrrect way to include javascript in a custom magento 2 theme?

Thanks in advance,

-Kevin

1

use link

    <link src="js/javascript.js" /> 
| improve this answer | |
  • Nothing still for some reason :l – Kevin.a Oct 13 '16 at 13:01
  • did you deploy the content after that php bin/magento setup:static-content:deploy – Qaisar Satti Oct 13 '16 at 13:01
  • I had to deploy it – Kevin.a Oct 13 '16 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.