JavaScript
in package
Utility for including JavaScript
When targeting modern browsers only, this class is not useful. Instead
scripts can be included as <script type="module"> what is preferable.
This class is only useful, if support for somewhat older browsers is still
desired or even required.
Tags
Table of Contents
Methods
- include() : void
- Loads the given local script
- includePolyfills() : void
- Includes polyfills for a few browser APIs
Methods
include()
Loads the given local script
public
include(string $filenameWithoutExt) : void
Uses the minified version (.min.js) if available and newer than the plain
version (.js). The query parameter ts is added to the src URL,
so the browser will not retrieve out-dated JavaScript from its cache.
Writes the respective <script> element to $bjs once,
even when called multiple times with the same argument. The script is
loaded as classic script (i.e. default type), and with the defer
attribute set.
Parameters
- $filenameWithoutExt : string
includePolyfills()
Includes polyfills for a few browser APIs
public
includePolyfills() : void
These are just filling some most basic needs, and are supposed to always fit in a small amount of JavaScript (certainly less than dozens or even hundreds of KB); currently about 0.5 KB minified.