meteorhacks / meteor-inject-initial

Allow injection of arbitrary data to initial Meteor HTML page
Other
78 stars 11 forks source link

Combine multiple injects #10

Open Nemo64 opened 10 years ago

Nemo64 commented 10 years ago

Just as an idea, if multiple packages inject stuff into the app there are multiple script tags. Alone my translator package injects 2 things and because of that there are 2 script tags. This also pollutes the global id namespace.

<script id='translator-namespaces' type='application/ejson'>{"both/l10n/public":{"de_DE":1,"en_US":1}}</script>
<script id='translator-language' type='application/ejson'>{"$type":"Translator.LanguageArray","$value":"de_DE de en_US en"}</script>

I just thought if it would be possible to combine all object injects into one with an id that is long enough to not interfere with other id's.

<script id='inject-initial' type='application/ejson'>{
"translator-namespaces":{"both/l10n/public":{"de_DE":1,"en_US":1}},
"translator-language":{"$type":"Translator.LanguageArray","$value":"de_DE de en_US en"}}
</script>
gadicc commented 8 years ago

Sorry for the late reply :)

Instead of:

Inject.obj('translator-namespaces', {...});
Inject.obj('translator-language', {...});

Can't you just:

Inject.obj('translator', {
  namespaces: ...
  language: ...
});

Yeah, it could be nice to save on the bytes for cases where multiple / different packages are all using it. I do think though that it's quite nice to so clearly see where all the data comes from, but I guess in production the speed is more important. So yes, this is definitely something we can consider.