Domanda

This is my first time actually using Meteor, I am trying to load JS files using the Meteor Framework and I have come to a complication where I want to do the following:

    <script type="text/javascript">
        document.write('<script src=' +
        ('__proto__' in {} ? 'js/vendor/zepto' : 'js/vendor/jquery') +
        '.js><\/script>')
    </script>

I want to load specific JS files based on certain conditions.

I understand that Meteor has a way of loading JS files where they would load deepest first, then alphabetically. Obviously if I put the scripts in the client folder then it would load both js files anyway without a care in the world. What would be the best way to load the files dynamically as the code above?

Thanks

È stato utile?

Soluzione 2

Meteor ignores folders that begin with '.'

A solution would be to throw everything that would be included conditionally into a folder named something like '.includes' and using conditional statements anywhere else in your Meteor project to include them with something like

require(path_to_that_folder + 'filename.js');

See:

http://docs.nodejitsu.com/articles/getting-started/what-is-require

http://nodejs.org/api/modules.html

Altri suggerimenti

With Meteor 1+ you should only 'load' files from your private and public folders. Using direct read/write for paths outside of your private and public directory is likely to fail since the file paths change between Meter development and deployment.

For the client you can can access any files in your public directory using a path relative to your public directory. For example $.getScript() can be used to access scripts in your public folder. For the server you can access any file in your private directory using Assets.getText() or Assets.getBinary() again using a relative path from your private directory.

In both cases do not include either private or public in the relative path. If your file is at 'public/foo/yoo.js' specify just 'foo/yoo.js'.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top