Meteor - How to download JS library only for specific users?

I am developing an administration interface with graphics and so on, and I am using the Highcharts library (140kb). I want this file to be downloaded only for admin users. What would be the best way to do this?

I just saw that we can use Iron-Router to conditionally load JavaScript , but I don't like the idea of ​​handling such things inside the router, as shown below:

Router.map ->
  @route 'admin',
    path: '/admin'
    template: 'admin'
    action: ->
      $.getScript '/js/moment.min.js', (data, textStatus, jqxhr) ->
        if jqxhr.status is 200
          @render()

NOTE . I wrote a short blog post to download the library only for specific users using Meteor. p>

+4
source share
1 answer

( )?

var loaded = false;
Deps.autorun(function() {
    if (!loaded && isAdmin(Meteor.userId())) {
        $.getScript("/js/moment.min.js");
        loaded = true;
    }
});
+3

Source: https://habr.com/ru/post/1546548/


All Articles