Skip to content

Is assets lazy? #1750

Answered by ethanshar
MuhammedKpln asked this question in Q&A
Discussion options

You must be logged in to vote

In order to have the assets lazy loaded I suggest loading the assets as an object of getters, like this

const icons = {
  get check() {
    return require('./check.png');
  },
  get checkSmall() {
    return require('./check-small.png');
  },
  get plusSmall() {
    return require('./plusSmall.png');
  },
  get search() {
    return require('./search.png');
  },
  get x() {
    return require('./x.png');
  }
};

Assets.loadAssetsGroup('icons', icons)

This way each assets will be loaded only once they've been actually used.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ethanshar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants