Requirements
class Requirements implements Flushable
Requirements tracker for JavaScript and CSS.
Config options
disable_flush_combined | bool | Flag whether combined files should be deleted on flush. |
Methods
Triggered early in the request when a flush is requested
Enable combining of css/javascript files.
Checks whether combining of css/javascript files is enabled.
Set the relative folder e.g. 'assets' for where to store combined files
Set whether to add caching query params to the requests for file-based requirements.
Check whether we want to suffix requirements
No description
Register the given JavaScript file as required.
Register the given JavaScript code into the list of requirements
Return all registered custom scripts
Register the given CSS styles into the list of requirements
Add the following custom HTML code to the section of the page
Include the content of the given JavaScript file in the list of requirements. Dollar-sign variables will be interpolated with values from $vars similar to a .ss template.
Register the given stylesheet into the list of requirements.
Registers the given themeable stylesheet as required.
Registers the given themeable javascript as required.
Clear either a single or all requirements
Restore requirements cleared by call to Requirements::clear
Block inclusion of a specific file
Remove an item from the block list
Removes all items from the block list
Update the given HTML content with the appropriate include tags for the registered requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, including a head and body tag.
Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given HTTP Response
Add i18n files from the given javascript directory. SilverStripe expects that the given directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js, etc.
Concatenate several css or javascript files into a single dynamically generated file. This increases performance by fewer HTTP requests.
Return all combined files; keys are the combined file names, values are lists of files being combined.
Delete all dynamically generated combined files from the filesystem
Deletes all generated combined files in the configured combined files directory, but doesn't delete the directory itself
Re-sets the combined files definition. See {@link Requirements_Backend::clear_combined_files()}
Do the heavy lifting involved in combining (and, in the case of JavaScript minifying) the combined files.
Set whether you want to write the JS to the body of the page rather than at the end of the head tag.
Set whether to force the JavaScript to end of the body. Useful if you use inline script tags that don't rely on scripts included via {@link Requirements::javascript()).
Output debugging information
Details
at line 25
static
flush()
Triggered early in the request when a flush is requested
at line 37
static
set_combined_files_enabled(bool $enable)
Enable combining of css/javascript files.
at line 46
static bool
get_combined_files_enabled()
Checks whether combining of css/javascript files is enabled.
at line 55
static
set_combined_files_folder(string $folder)
Set the relative folder e.g. 'assets' for where to store combined files
at line 67
static
set_suffix_requirements(bool $var)
Set whether to add caching query params to the requests for file-based requirements.
Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by filemtime. This has the benefit of allowing the browser to cache the URL infinitely, while automatically busting this cache every time the file is changed.
at line 76
static bool
get_suffix_requirements()
Check whether we want to suffix requirements
at line 88
static
backend()
at line 100
static
set_backend(Requirements_Backend $backend)
Setter method for changing the Requirements backend
at line 109
static
javascript(string $file)
Register the given JavaScript file as required.
at line 119
static
customScript(string $script, string|int $uniquenessID = null)
Register the given JavaScript code into the list of requirements