{"id":21931731,"url":"https://github.com/lekoala/silverstripe-defer-backend","last_synced_at":"2026-05-03T09:38:57.923Z","repository":{"id":62516758,"uuid":"321351520","full_name":"lekoala/silverstripe-defer-backend","owner":"lekoala","description":"Defer your requirements in SilverStripe","archived":false,"fork":false,"pushed_at":"2024-02-08T12:34:12.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-06T03:52:44.970Z","etag":null,"topics":["backend","csp","defer","silverstripe"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lekoala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"lekoala"}},"created_at":"2020-12-14T13:11:13.000Z","updated_at":"2022-03-25T11:23:08.000Z","dependencies_parsed_at":"2023-01-22T15:45:08.347Z","dependency_job_id":"7c4f542f-707d-4e38-957e-ad6fc48f4336","html_url":"https://github.com/lekoala/silverstripe-defer-backend","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"1d77fdd57a346c6e5271893e2862f12fb47c17fd"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/lekoala/silverstripe-defer-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekoala%2Fsilverstripe-defer-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekoala%2Fsilverstripe-defer-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekoala%2Fsilverstripe-defer-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekoala%2Fsilverstripe-defer-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lekoala","download_url":"https://codeload.github.com/lekoala/silverstripe-defer-backend/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lekoala%2Fsilverstripe-defer-backend/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269083266,"owners_count":24357143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","csp","defer","silverstripe"],"created_at":"2024-11-28T23:14:52.056Z","updated_at":"2026-05-03T09:38:57.917Z","avatar_url":"https://github.com/lekoala.png","language":"PHP","funding_links":["https://github.com/sponsors/lekoala"],"categories":[],"sub_categories":[],"readme":"# SilverStripe Defer Backend module\n\n[![Build Status](https://github.com/lekoala/silverstripe-defer-backend/actions/workflows/ci.yml/badge.svg)](https://github.com/lekoala/silverstripe-defer-backend/actions)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lekoala/silverstripe-defer-backend/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lekoala/silverstripe-defer-backend/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/lekoala/silverstripe-defer-backend/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lekoala/silverstripe-defer-backend/?branch=master)\n[![Build Status](https://scrutinizer-ci.com/g/lekoala/silverstripe-defer-backend/badges/build.png?b=master)](https://scrutinizer-ci.com/g/lekoala/silverstripe-defer-backend/build-status/master)\n[![codecov.io](https://codecov.io/github/lekoala/silverstripe-defer-backend/coverage.svg?branch=master)](https://codecov.io/github/lekoala/silverstripe-defer-backend?branch=master)\n\n[![Latest Stable Version](https://poser.pugx.org/lekoala/silverstripe-defer-backend/version)](https://packagist.org/packages/lekoala/silverstripe-defer-backend)\n[![Latest Unstable Version](https://poser.pugx.org/lekoala/silverstripe-defer-backend/v/unstable)](//packagist.org/packages/lekoala/silverstripe-defer-backend)\n[![Total Downloads](https://poser.pugx.org/lekoala/silverstripe-defer-backend/downloads)](https://packagist.org/packages/lekoala/silverstripe-defer-backend)\n[![License](https://poser.pugx.org/lekoala/silverstripe-defer-backend/license)](https://packagist.org/packages/lekoala/silverstripe-defer-backend)\n[![Monthly Downloads](https://poser.pugx.org/lekoala/silverstripe-defer-backend/d/monthly)](https://packagist.org/packages/lekoala/silverstripe-defer-backend)\n[![Daily Downloads](https://poser.pugx.org/lekoala/silverstripe-defer-backend/d/daily)](https://packagist.org/packages/lekoala/silverstripe-defer-backend)\n\n## Intro\n\nThis module allows you to define a backend that defers your script by default.\nAs a nice bonus, it also allows you to set a simple content security policy by adding nonce to your scripts.\n\n## Defer your requirements\n\nIn order to defer your scripts, you need to replace in your `PageController` the default backend.\n\n```php\nprotected function init()\n{\n    parent::init();\n\n    DeferBackend::replaceBackend();\n}\n```\n\nOnce this is done, all scripts (provided by modules or yourself) will be deferred. This is great\nfor performance because all scripts become non blocking and load order is preserved.\nScripts are added in the head, since they are not blocking, the browser can load them while parsing\nthe html.\n\n### Inline scripts\n\nDeferring inline scripts is not possible as such. But since events are fired once the dom is parsed,\nyou can wrap your scripts like so\n\n```js\nwindow.addEventListener('DOMContentLoaded', function() { ... });\n```\n\nThis module automatically does this. Be aware that if you rely on global variables, you might want to\nprevent this from happening by adding a comment with `//window.addEventListener` somewhere. This\nwill prevent our class to automatically wrap your script.\n\n### Css order\n\nThis module also check your css files and make sure your themes files are loaded last. This make\nsure that your styles cascade properly.\n\n## Themed javascript\n\nYou can pass an array of options instead of just \"type\" parameter.\n\n## Cookie consent\n\nIn order to support my [cookieconsent module](https://github.com/lekoala/silverstripe-cookieconsent) you\ncan now pass an additionnal option \"cookie-consent\" to your javascript files to load them conditionnaly.\n\n```php\nRequirements::javascript('myscript.js',['cookie-consent' =\u003e 'tracking']);\n```\n\nThis also work (kind of) for custom scripts. Since the requirements api does not support anything\noutside script and uniquenessID, we append the cookie type to the uniquenessID id\n\n```php\nRequirements::customScript($script, \"ga-tracking\");\n```\n\n## Security headers\n\nAs a small bonus, this module allows you to add two security headers:\n\n-   Referrer-Policy\n-   Strict-Transport-Security (only if https is enabled)\n\n```php\npublic function handleRequest(HTTPRequest $request)\n{\n    $response = parent::handleRequest($request);\n\n    CspProvider::addSecurityHeaders($response);\n\n    return $response;\n}\n```\n\n## Js modules support\n\nIf you want to use [native js modules](https://javascript.info/modules-intro), this can\nbe done with the following config flag:`\n\n```yml\nLeKoala\\DeferBackend\\DeferBackend:\n    enable_js_modules: true\n```\n\nJs modules are deferred by default as well. In addition, script with `type=module` are only\nloaded by modern browser, which can be really nice if you want to use modern browsers\nand let other older browsers experience a js-less webpage.\n\nThis allows you to use native es6 syntax without bundlers like webpack, etc. at the cost\nof not supporting older browsers.\n\n## Content security policy\n\nThis module also add random nonce to your scripts. This allows you to setup a simple\nContent Security Policy.\n\nAlso, a `$getCspNonce` is made available in your templates.\n\n```php\npublic function handleRequest(HTTPRequest $request)\n{\n    $response = parent::handleRequest($request);\n\n    CspProvider::addCspHeaders($response);\n\n    return $response;\n}\n```\n\nPlease note that the csp is disabled by default. You might want to enable it with the following config:\n\n```yml\nLeKoala\\DeferBackend\\CspProvider:\n    enable_csp: true\n    csp_report_uri: \"https://my-url-here\"\n    csp_report_only: false\n```\n\nConsider setting this to `csp_report_only` at the beginnning because enabling csp can break your website.\n\n## Compatibility\n\nTested with ^6\n\nUse previous branch for v4/v5\n\n## Maintainer\n\nLeKoala - thomas@lekoala.be\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flekoala%2Fsilverstripe-defer-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flekoala%2Fsilverstripe-defer-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flekoala%2Fsilverstripe-defer-backend/lists"}