If I have two components (on a single page) that both reference the same JavaScript Static Resource using an <apex:includescript> tag, will the script be included twice?


If you use the same <apex:includeScript /> tag multiple times, the JavaScript will only be included once. Don't forget to use {!URLFOR($Resource.scriptJs)} :-)

Best to load your libraries using <apex:includeScript> and then perform any component-specific invocations inside <script>...</script> tags.

| improve this answer | |

If I remember correctly this is the only reason why you would use <apex:includescript> to avoid having the same javascript file included twice via components

Otherwise you would just use <script type='text/javascript' src='/resource/1233160164000/example_js'>, because that would run a bit faster, and you can place your <script> at the bottom of the page (this way your page will load faster)


Edit: For the person that downvoted me, this behaviour is actually described in the documentation: apex:includeScript

For performance reasons, you may simply want to use a JavaScript tag before your closing <apex:page> tag, rather than this component.

| improve this answer | |

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.