Preventing package load until app is on a certain route or template

I’m using the Meteor CodeMirror package at the moment for one route / template in my app.

I only need it for that one route / template, and it’s super useful, so in an ideal world, I’d only incur the overhead of loading it for that route / template.

CodeMirror’s a pretty involved package, so while I’m aware that it’s possible to conditionally load scripts with Jquery, I’d prefer to do it on a package basis.

The other reason that this is my preferred approach is that there are a few other packages that I’d like to use for specific Routes / Templates, and this strikes me as a conceptually clean way to do things (even if it happens to get messy in implementation).

Anyone got views on the best way to do it? Have I missed something obvious?

You might want to look at this package

I was looking at numtel:lazy-bundles just yesterday because I wanted to compile templates on certain routes but I thought that it was just for lazy loading templates and helpers. I thought packages were always pulled in at meteor build?

1 Like