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.

`callback` option for loading scripts

See original GitHub issue

Currently, useHead does not provide a vue-meta-like callback function to do something when a script has been loaded.

It’d be a nice DX feature IMO ☺️

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
harlan-zwcommented, Nov 14, 2022

This is available in v1, documentation is here: https://unhead.harlanzw.com/guide/guides/dom-event-handling

If you insert the script client side only, then onload is guaranteed to run as it won’t set the src until the event listener is attached

1reaction
harlan-zwcommented, Nov 10, 2022

Ah I think there’s a larger bug actually in that stackblitz setup, it’s not removing the script when you click it a second time 🤔

The issue you mention is also there though, can be replicated by adding the same script in App.vue. A straightforward solution is just to set some global ref wherever you’re loading the script but I might be able to tinker with it so the onload always fires

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction: callbacks - The Modern JavaScript Tutorial
The script is executed “asynchronously”, as it starts loading now, but runs later, when the function has already finished. If there's any code ......
Read more >
Asynchronous Script Loading Callback - Stack Overflow
Async function with callback: · 1. The line o.u = '//' + u; should read o. · 2. s. · 1 · I...
Read more >
Async Script Loader with Callback - CSS-Tricks
The success callback for jQuery.getScript is called once the script has been downloaded, but it's not guaranteed to be called after the script...
Read more >
Dynamically loading multiple assets with a callback
I wanted to load the CSS and JavaScript in parallel and fire a callback function when both of them had finished loading. Here's...
Read more >
JavaScript Introduction:callbacks | W3Docs Tutorial
function loadScript(src) { //creates the <script> tag and adds it to the page, after which // the script with the given src starts...
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