Download the PHP package souldigital/silverstripe-headjs without Composer
On this page you can find all versions of the php package souldigital/silverstripe-headjs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download souldigital/silverstripe-headjs
More information about souldigital/silverstripe-headjs
Files in souldigital/silverstripe-headjs
Package silverstripe-headjs
Short Description Use headjs to load requirements in Silverstripe
License BSD-3-Clause
Informations about the package silverstripe-headjs
Silverstripe HeadJS Backend
================== Use HeadJS for assets loading.
Compatibility
================== Tested with Silverstripe 3.1
Features
==================
- Async loading of requirements using the native Requirements engine
- Specific targeting of requirement locations in DOM via SectionedHeadJsBackend
- Critical js/css files to be required in the head while all other requirements are loaded above the closing body
- Add JS callbacks to requirements
- Add dependencies to JS / CSS files
How do I use this thing?
==================
Setup
If you just want to use the HeadJS integration for your Requirements backend, add the following to your mysite/_config.php
Requirements::set_backend(Injector::inst()->get("HeadJsBackend"));
If you'd like to use the Sectioned Head JS, add the following to your mysite/_config.php
Requirements::set_backend(Injector::inst()->get("SectionedHeadJsBackend"));
Adding a callback
An example of adding a callback to a CSS or JS requirement is below:
Adding a dependency
An example of adding a dependency to a CSS or JS requirement is below:
In the example above, we require jQuery UI, but make sure that it is only loaded after jQuery has loaded. Note that we can add multiple dependent files to the jQuery JS file if we want, but there is a limitation around chaining dependencies; i.e. we can only have a single level of dependency - in the example above, we can not add a new file that is dependent on jQuery UI.
Specifying a section
An example of specifying a section for a CSS or JS requirement is below:
Super-specific bugs and their associated fixes
UserForms module validation won't work (it says it can't find jQuery)
There are lots of different ways we can solve this issue, but the simplest one I've found is if you add an extension to the UserDefinedForm_Controller - or even just edit Page_Controller - and add the following to the init() function:
Maintainer
Tim - [email protected]
Original Repo
silverstripe-headjs by the awesome lekoala