I’m trying to integrate UploadCare into my project: https://uploadcare.com/documentation/widget/
Basically I need to add this:
<script src="https://ucarecdn.com/widget/2.5.9/uploadcare/uploadcare.min.js" charset="utf-8"></script>
And then just set the public_key:
<script>
UPLOADCARE_PUBLIC_KEY = 'demopublickey';
</script>
How can I guarantee that the script uploadcare.min.js
is loaded after jquery and the rest of the necessary Meteor JS code/files?
Google leads me to old blog posts, outdated StackOverflow answers and ugly hacks like listening to Template.onCreated
and $.getScript
.
Check out the docs on Structuring your app to learn about the load order of files, then place the file where needed (for example, a lib folder). Another alternative would be to use Meteor 1.3 modules to have maximum control of the order that your scripts are loaded in.
classic race condition, no matter what they tell you will risk to have random bugs which are very hard to fix.
My suggestion is to have a specific function to do this stuff which:
- Launches
- Check a lock variable to see if it’s the first time running
- If yes run, if no exit
- Set lock variable to true
- Exit
And this function should be called with modules. Otherwise Tracker will run it multiple times causing race conditions that will fucks everything up.