Building multi-page app in meteor

Hello Guys,

I wanted to know whether it is possible to add different css and js file for each template created?

i have created a multiple page project and when i run the project it include all the css and js for all page.But i want to include css and js for specific templates only and not entire project.

it would be great if someone can guide me on how this can be achieved?

The Meteor build process concatenates all of the CSS and JavaScript into one file. This helps users with a slower network speed get your app faster and make less network requests.

To use JavaScript on the template level, use Template helpers, events, and triggers like onCreated.
To use CSS on the template level, make specific classes in your CSS that are just for that template.

1 Like

Meteor 1.3 will introduce modules (import/export) which is what you want


Is there any example which i can refer in order to get more idea about it

There’s a number of options

  • check es6 modules on Google and read
  • download the meteor1.3 beta and try it out
  • wait for official 1.3 release

Edit: here is more about how it’ll work. Import/export keywords

The current 1.2 build system bundles all html, css and js within the applications and packages client scope and sends it all when the application url is used.

The current system by default does not support sending only css and js for specific templates, it will send the entire project.

Even with the current ES6/2015+ modules import and export support in 1.3, although it will support lazy evaluation via the imports folders.

If you want to achieve what you want you’ll have to work with Server Side Rendering and or use a bundler that supports code splitting for incremental/conditional/progressive/lazy/etc loading such as Webpack, and likely you also need to account for it in your routing setup.

There are no known code splitting solutions for blaze, with Meteor I have only encountered known working examples with react and webpack. Among other frameworks/integrated stacks I’ve encountered donejs, which is not using react, but still have code splitting using a template system that looks like spacebars used with blaze, it used systemjs and webpack I think to remember.

If Meteor will ever support code splitting without webpack and similar, it’s not going to happen before a number of other areas are covered first, so it seems.

1 Like