Search code examples
javascriptmeteoriron-router

Making Meteor to exclude certain JS files for anonymous users


What would be the best approach when there's a need to:

  1. deploy a Meteor.js app to meteor.com and
  2. exclude certain JS files from being bundled and accessed by anonymous users

So far I've understood that this is only possible via placing the files in question in the public folder and then conditionally loading them.

Is there another possibility, namely one that would allow keeping the files needed to be loaded conditionally in the client/templates.

Thanks so much!

Jussi


Solution

  • Meteor intends to send all code to the client in it's build bundle. That being said, your public and conditionally apply method works, or you can write code that allows the functions to only be ran by people who are logged in. If you're using the Meteor Accounts package, that's as simple as

    if(Meteor.user){
        //logged in
    } else {
        //not logged in
    }