0

I want to render the some scripts but it seems they are not loaded in my jade file although the block content gets loaded

Here is the code:

script(type='text/javascript' src="https://www.gstatic.com/firebasejs/4.5.0/firebase.js")

script(type='text/javascript' src="/../scripts/main.js")
extends layout

block content
  h1= title
  p Welcome to #{title}
6
  • Have you inspected your DevTools => Network tab and ensured that it is showing any 404 error(s) for these script inclusions? Commented Oct 9, 2017 at 6:59
  • Yea, it's not even making a request for the file Commented Oct 9, 2017 at 6:59
  • Have you kept your script declarations under head ? Commented Oct 9, 2017 at 7:02
  • Yea, I figured it out just now, it's working after I keep it under the head.. noob mistake though! Commented Oct 9, 2017 at 7:03
  • I will put this as an answer, Can you please accept it? :) Commented Oct 9, 2017 at 7:09

1 Answer 1

1

You will have to put your script tags under head block in your Jade templates.

Your code should look like,

  extends layout
  append head
    script(type='text/javascript' src="https://www.gstatic.com/firebasejs/4.5.0/firebase.js")

    script(type='text/javascript' src="/../scripts/main.js")

    block content
      h1= title
      p Welcome to #{title}

Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

Are you sure it would not throw error? Because I think this is a child template, so it should only define block's. pugjs.org/language/inheritance.html#common-mistakes
@MohitBhardwaj My Bad, I didn't realize that.. In that case we should be using the append head keyword (if I'm not wrong).
Yeah, I think either we need to include the scripts in the parent template i.e. layout.pug in this case. Or if that is not desired for any reason, we can include them inside block content, or by creating another block, something like block footer etc.

Your Answer

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.