void add_script( script, version, cdn, defer, ie_conditional, ie_only_conditional, async, onload, preload, nomodule, type, class, data, priority )
Include a Javascript file into the page.
- script
URL of the script to include.
- version
The version number of javascript. If not provided, no specific version of Javascript is assumed.
- cdn
Pass false to prevent the script from being loaded through the CDN on the front-end. Default behavior if no value is specified is to load through the CDN.
- defer
Pass true to add the include to the bottom of the page's
. Default behavior is to add the include to the page's .- ie_conditional
Wrap the include in an IE conditional comment with the passed value set as the expression. IE will ignore the include unless the expression evaluates to true. Non-IE browsers will see the include. Overrules ie_only_conditional
.
- ie_only_conditional
Like ie_conditional
, but non-IE browsers will ignore the include.
- async
If set, async will be used. This automatically disables the defer option.
- onload
Javascript code that should be run as soon as the script loads. Useful for combining with 'async' as needed.
- preload
If provided, a Link HTTP header will be added with a directive to preload the script in question. Should be used on critical path items, but sparingly since this contributes to header weight.
- nomodule
If provided, the nomodule attribute will be applied to the tag. The nomodule attribute targets legacy browsers that are not capable of loading modules.
- type
If provided, a type attribute will be set to the provided value. Note that tag is XHTML compliant and will add CDATA tags designed for the use of javascript - so this can only be switched to tag types that allow for JS commenting.
- class
If provided, will add a class
attribute with the corresponding CSS class(es) associated to the script tag.
- data
If provided, each key in the provided array will be added as an attribute to the script tag with a prefix of data-
and be given the associated value that is passed.
- priority
The higher the value, the earlier the script will be loaded relative to other scripts that are added on the page. Note that some scripts cannot be bypassed as they are given the highest possible value for priority.