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

Qaisar Satti
32.6k18 gold badges88 silver badges138 bronze badges
asked Oct 13, 2016 at 12:54

1 Answer 1

1

use link

 <link src="js/javascript.js" /> 
answered Oct 13, 2016 at 12:57
3
  • Nothing still for some reason :l 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 Commented Oct 13, 2016 at 13:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.