question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SCRIPT and LINK tags defined in HEAD incorrectly assigned to BODY

See original GitHub issue

It appears the script and link tags defined in the head section are incorrectly being placed in the body DOM tree when using selectors to find them. On the plus side this doesn’t apply to $('body').html() text, but it does make using cheerio to build up template pages impossible without either duplicating script and link tags (i.e. when you’re passing the links up and searching for script and link tags via body > script or body > link) or adding additional markup to concatenate the script and link head elements (like moving them outside of the head into a div contained in the body.

This does work in standard jQuery (i.e. you can use head > link and head > script to obtain either.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
CoryGHcommented, Aug 20, 2017

Upon closer inspection this only occurs when you have a custom element preceeding the tags in the head tag, for instance:

<head>
    <title>title</title>
    <link rel="stylesheet" href="/path/to/mathquill.css"/>
    <header>header</header>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>

In the example above the link tag will show up but the script tag gets moved into the body (but not in the body HTML.) This differs from jQuery, which will always place it in the head tree.

Additional note: it does actually copy the non-standard tags into the start of the body html (for instance the header tag above,) but doesn’t not copy the other elements into the body.

0reactions
inikulincommented, Aug 26, 2017

You can add any tags inside template.

Read more comments on GitHub >

github_iconTop Results From Across the Web

script tag doesn't work in head tag - Stack Overflow
Any JS written in the head will be parsed before the body begins to load, so any JS statements referencing body elements will...
Read more >
Scripts in HTML documents - W3C
The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of...
Read more >
What's in the head? Metadata in HTML - MDN Web Docs
The HTML head is the contents of the <head> element. Unlike the contents of the <body> element (which are displayed on the page...
Read more >
1. Loading and Execution - High Performance JavaScript [Book]
The HTML 4 specification indicates that a <script> tag may be placed inside of a <head> or <body> tag in an HTML document...
Read more >
Custom code in head and body tags - Webflow University
<link>, <meta>, and <style></style> tags should always go inside the <head> tag. <script></script> tags can also be added inside the <head> tag, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found