Wait on images in iron:router

I have a small web app with about 60 documents in a collection. One of the fields is an image path. Is it possible to waitOn those images to load into the client before rendering the template? What’s the best way to preload images with meteor?

4 Likes

just bumping this. anyone have experience preloading images with meteor?

I’d like to know too! If anyone has the answer…

I’m not sure if I understand your question right, but I think I had a similar problem today:

I got a console error, when I refreshed the page that contained my images.
Nothing was breaking, but I still got the error.

I found out that this was due to my image collection not being ready before rendering.
After some fiddeling around I found this in the iron router docs:

Router.route('/detailspage/:_id', {
  loadingTemplate: 'loading',

  waitOn: function () {
    return Meteor.subscribe('images');
  },

  action: function () {
    this.render('myTemplate');
  }
});

This worked for me.
Maybe it helps.

What does the publish side look like?

1 Like