6

If I have a parent lightning component and the component has ltng:require do I need to require the same libraries from the children components or will the inclusion be propagated to children?

For example the parent lightning component has the following tag inside it:

<ltng:require scripts="{!join(',', $Resource.fooLib1, $Resource.fooLib2)}"/>

If I want to be able to access the fooLib1 in the child component do I need have the following tag in the child:

<ltng:require scripts="{!$Resource.fooLib1}"/>

?

Are there any performance difference? Will the Lightning optimize such inclusions and include the libraries only once (in case the propagation happens in Lightning and in case it is present)?

I tried to google that, but found nothing about it. Will be grateful for any information source provided.

4

The documentation doesn't specify, as far as I can tell, but both of your statements are currently correct: a library loaded in a parent component is also available in the child component, and a library included twice is loaded only once. However, since the documentation makes no claims about how SecureWindow exposes these libraries, the optimal solution is to load a library in each component that needs it. There's no real performance penalty, since the library is loaded only once, and you would rather have the library be available than not.

  • How did you check that the library is loaded only once? Did you use Chrome Dev Tools somehow? – Yaroslav Trofimov Jun 13 '18 at 15:34
  • @YaroslavTrofimov Yes, I used the Network tab to verify that the server was queried only once for that file. – sfdcfox Jun 13 '18 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.