-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return a Promise for async scripts? #240
Comments
The example you mentioned is already possible (maybe in the mean time) and generates the following html: <script src="/someAsyncScript.js" async></script> So I think we can close this issue or did I not understand your request? |
@pimlie He is looking for sth. like a We actually need a solution for this common problem. |
Any suggestions would be appreciated, I am struggling a bit with how this would work with ssr generated code (unless we dont render the code that should run afterwards on ssr). |
@pimlie well, for SSR that part shouldn't matter much if I recall correctly. What are your concerns there? |
Maybe I still dont understand the problem, but am I correct you need a solution for eg the problem I have with nuxt-matamo where I load an external library that sets |
@pimlie exactly. we can use the |
Yeah exactly, thats what I meant with not rendering them on ssr if we'd need to dynamically create script tags to add an onload listener. With some fancy stuff we could probably ssr the first nodes of an async branch (and use an onload attribute in the html with some global reference) but all childs still need to be dynamically created then and cant be rendered on ssr I guess. That might also have an effect on render performance |
@pimlie We'd have to test when the external scripts injected through vue-meta are loaded when using SSR first (timing-wise). I know there are differences between the first render and the navigation across routes in SPA mode too. In the worst scenario we could make that feature SPA-mode only (where it's most useful IMO) |
hmm yes, and we could still preload those child script files which means the render performance shouldnt be effected that much I guess |
Btw, I am looking for suggestions how the api for this functionality should look like (especially from a SSR point of view). We would probably need to be able to run the listener in the local component scope, but the onload will always be on the global scope. Potential issues I see are:
We could probably take a look at vue-script2 for inspiration as well. My first idea would be that its probably easiest to just fire some events on the |
If you use dynamic page URLs (e.g. with article ID) and going to the same page with a different ID, the callback will not be called. But I think it should. |
I use a workaround for this issue, but I assume it's a bug.
|
Hi,
Is it possible to a Promise when loading async scripts with vue-meta? So that code that are needed to be executed after the script is loaded won't run into error.
For example a script like this:
The text was updated successfully, but these errors were encountered: