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.

Inject script content into <head>

See original GitHub issue

Hey, thanks for your awesome work! How can I inject script content directly into <head> tag, since

<!-- inject:js -->
<!-- endinject -->

is not valid inside <script> tag? Same with css contents. How can I inject css code right into the <style> tags inside <head>? Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ganlanyuancommented, Dec 31, 2016

@ansballard Thanks a lot! It works now.

1reaction
ansballardcommented, Dec 30, 2016

You’re injecting into an html file, so the library assumes your start and end tags will be html comments. You’ve specified a start tag, but not an end tag, so that’s probably the issue.

// ...
{
  starttag: '/* critical:css */',
  endtag: '/* endinject */'
  // ...
}
// ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically inject script into <head>? - Stack Overflow
if you want to add a script tag with src attribute to head you should use. var script= document.createElement('script'); script.src ...
Read more >
Need help in injecting script to page head before DOM gets ...
I was trying to inject a script into a webpage with chrome extension before the page starts loading the dom using "content script"...
Read more >
Where to put a script tag — into head or body end? - Medium
For the script to work it needs to be executed only after the target <div id=”root”>LOADING</div> is included into the DOM. For that...
Read more >
How to add content in <head> section using jQuery/JavaScript?
head property: The head property of the document returns the head element of the document. Any new content can be added to this...
Read more >
Add script into head section - DotNetNuke
Hi, As I am a new at DNN CMS I would like to ask for some help.I have problems with adding scripts into...
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