-
Notifications
You must be signed in to change notification settings - Fork 308
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
Allow async init #407
Comments
FYI, I was able to make a custom version of this work. I created a modified version of the lazy loader snippet. It has the same API (although I rewrote it, and changed the actual implementation a bit), but instead of using a script tag, it uses an I then tell Vite (our build tool) to alias const alias = (modId: string, filePath: string) => path.join(path.dirname(require.resolve(modId)), filePath)
{
resolve: {
alias: {
'mixpanel-browser': alias('mixpanel-browser', 'mixpanel.min.js'),
}
}
} This file is the minified version of the CDN file. Everything works, so there is no reason this can't be implemented by the mixpanel team. The only 'downside' is that my solution still uses the global |
@bfricka, this way you are just bundling the version that is loaded by the snippet, which changes the global It will either increase your bundle size by ~50kB, if you do a synchronous import, or you'll have a blind spot until the asynchronous import is loaded, because until it is loaded there is no mixpanel object nor an event queue. My proposal is for Mixpanel to make the basic queue the snippet creates available in the NPM package, while allowing us to connect our async loading mechanism (normally |
@romulof Sorry, but you're completely wrong. The way I'm doing it has no blind spot, because the snippet code is a stub queue that handles all calls synchronously. These queued calls are then handled by the full library when it's loaded asynchronously. It also doesn't increase the bundle size by more than the size of the snippet (which is just over 100 gzipped bytes), since the main library is loaded async. But you seem to know better, so I guess you'll have to wait for someone to implement it for you. |
@romulof You are obviously incapable of understanding how I implemented this, so again, you'll just have to wait for someone to do it for you. |
I missed the "modified version of the lazy loader snippet" in your first comment, which defeats the purpose of requesting a feature here. I'm not looking for a solution. My problem has been fixed way before I posted it here. I just wanted Mixpanel to be aware of the problem and proposed an easy API to solve the issue for everyone. |
If we use the snippet, it creates a basic queue and loads the script asynchronously, so events can be tracked while the mixpanel lib is loaded. As a downside Adblockers can do their thing.
If we use the NPM package, we add 200kb of JS to our bundles and this cannot be loaded async unless we don't want to track things in background.
Loading async via NPM package can be tricky as different bundlers can handle things in different ways, although most use
import()
, so I suggest to make this initialisation in 2 steps:Example:
This way our bundlers can deploy mixpanel lib together with our applications, avoiding ad blockers, and we don't pay 200+kb bundle tax.
The text was updated successfully, but these errors were encountered: