PHPackages                             dorsetdigital/silverstripe-enhanced-requirements - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dorsetdigital/silverstripe-enhanced-requirements

ActiveSilverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

dorsetdigital/silverstripe-enhanced-requirements
================================================

Enhanced requirements for Silverstripe

v2.0.0(7mo ago)117.8k—0%5[2 issues](https://github.com/DorsetDigital/silverstripe-enhanced-requirements/issues)4BSD-3-ClausePHPPHP &gt;=8.2

Since Jun 14Pushed 7mo ago3 watchersCompare

[ Source](https://github.com/DorsetDigital/silverstripe-enhanced-requirements)[ Packagist](https://packagist.org/packages/dorsetdigital/silverstripe-enhanced-requirements)[ Docs](https://github.com/DorsetDigital/silverstripe-enhanced-requirements)[ RSS](/packages/dorsetdigital-silverstripe-enhanced-requirements/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (4)

silverstripe-enhanced-requirements
==================================

[](#silverstripe-enhanced-requirements)

Extends and enhances the Silverstripe requirements system, providing inlining of assets, http/2 server push, deferred css, etc.

*Note: This module is designed to provide a number of tools which may help to improve the front-end performance of a website. It is not an 'off-the-shelf' solution, and should be used carefully. Just setting everything to preload or push, or inlining content without first analysing where and how it's used can lead to a reduction in performance!*

Requirements
------------

[](#requirements)

- Silverstripe 4.x / 5.x - Please use the V1 branch
- Silverstripe 6.x - Use the V2 branch

Installation
------------

[](#installation)

Install with `composer require dorsetdigital/silverstripe-enhanced-requirements ^1`

Once installed, the module will set the Requirements system to use the enhanced backend, but none of the additional features will be enabled by default.

Usage
-----

[](#usage)

The module extends the standard `Requirements` methods, providing additional options. Currently, these additional options are available for both CSS and JS files:

- inline
- preload
- push
- nonce

The following option is also available for CSS files:

- defer

### inline

[](#inline)

When this option is set, the framework will attempt to add the provided CSS or JS file as inline code rather than being loaded externally. This allows developers to still build front-end assets with existing workflows, but inline the processed content where it is advantageous to do so:

```
Requirements::css('build/app.css', 'screen', ['inline' => true]);

```

```
Requirements::javascript('build/app.js', ['inline' => true]);

```

### preload

[](#preload)

The preload option automatically adds `` tags to the markup to help improve the load order of important assets

```
Requirements::javascript('build/critical.js', ['preload' => true]);

```

This would result in the following tag being added to the markup:

```

```

### push

[](#push)

The push option adds HTML link headers to the response. On systems where this is supported, this will trigger a server push of the specified assets in order for them to be delivered even before the browser has completed parsing the document.

```
Requirements::css('build/bundle.css', 'screen', ['push' => true]);

```

Would result in an HTTP header similar to the following being added to the response:

```
Link ; rel=preload; as=style

```

### nonce

[](#nonce)

This adds the HTML 'nonce' attribute as required. Can be useful for dealing with CSP implementations

### defer (css)

[](#defer-css)

If the defer option is added to a CSS inclusion, a tag will be injected into the head of the document which loads the specified CSS file after the page has loaded. This can help to reduce page blocking for styles which are not needed for the initial rendering. In order to provide support for browsers which do not run javascript, a noscript tag is also added. The resultant output looks like this:

```
