简体   繁体   中英

Javascript files in Meteor

So I have an app I'm working on, I've installed a few packages (namely twbs bootstrap, accounts and a few collections ones) and am starting to work on the way it looks. However, I'm trying to include a JS file that doesn't seem to be working.

Is there a good way to include js files, such as some jquery etc? I've noticed both jquery and my js file are being loaded in the head but just don't seem to be working. On my design (standard html page) the file is working fine, so the code isn't wrong.

I'm quite new with Meteor, so is there something I need to do with my routes or the way templates are loaded etc?

Any help would be much appreciated! I've looked everywhere :(

Tom.

Try not to include scripts as you normally would via the <script> tag. If I need a specific JS lib, my first step is to search on Atmosphere to see if someone else has wrapped it into a Meteor package. If not, you can always just take the .js file (unminified) and drop it into a folder such as /client/lib/third-party and it should work fine.

Without more details such as which script you're trying to get working, or without seeing your code, this is the best help I can offer. Give the above a shot and see how that works out.

In Meteor all files are "preprocessed" . By default all JS files are loaded (and executed) on the Client and the Server. This default locus is called common code. It is shared code between client and server. Common CSS files are only loaded on the client. Then there is client and server specific code. These js files are saved in certain places. client-side code is saved in /client , server side in /server .

This means that you'll want your code to be inside the /client directory. You might call the file /client/main.js . All Libraries included via packages (ex. jQuery) are available to these files.

I'd also strongly recommend reading this before going forward.

PS: jQuery is in the Meteor-Core and is guaranteed to stay in there so you don't have to manually add it. There's no harm to it dough and it might be considered good style.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM