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 Answer 1

1

use link

    <link src="js/javascript.js" /> 
3
  • Nothing still for some reason :l
    – Kevin.a
    Commented Oct 13, 2016 at 13:01
  • did you deploy the content after that php bin/magento setup:static-content:deploy Commented Oct 13, 2016 at 13:01
  • I had to deploy it
    – Kevin.a
    Commented Oct 13, 2016 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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