apex:includeScript

A link to a JavaScript library that can be used in the Visualforce page. When specified, this component injects a script reference into the <head> element of the generated HTML page.

Multiple references to the same script are de-duplicated, making this component safe to use inside an iteration component. This might occur if, for example, you use an <apex:includeScript> inside a custom component, and then use that component inside an <apex:repeat> iteration.

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

This component supports HTML pass-through attributes using the "html-" prefix. Pass-through attributes are attached to the generated <script> tag.

Example

<apex:includeScript value="{!$Resource.example_js}"/>

The example above renders the following HTML:

<script type='text/javascript' src='/resource/1233160164000/example_js'>

Attributes

Attribute Name Attribute Type Description Required? API Version Access
id String An identifier that allows other components in the page to reference the component. 13.0 global
loadOnReady Boolean Specify whether the script resource is loaded immediately, or after the document model is constructed. The default value of "false" loads the script immediately. Set to "true" to cause JavaScript referenced by the component to wait to be loaded until the page is "ready."

Scripts loaded this way will be added to the DOM after the onload event is triggered, instead of immediately. This event occurs after the DOM is constructed, but might be before child frames or external resources, such as images, have finished loading.

29.0
value Object The URL to the JavaScript file. This can be a reference to a static resource, a best practice, but can also be a plain URL. Yes 13.0 global
Previous
Next