toastnz/deferred-css
最新稳定版本:6.0.1
Composer 安装命令:
composer require toastnz/deferred-css
包简介
A Silverstripe CMS module for deferred CSS loading.
关键字:
README 文档
README
This module customises Silverstripe's requirements backend to defer CSS loading using the preload pattern.
It overrides includeInHTML() and rewrites stylesheet links to:
<link rel="preload" as="style" href="..." onload="this.onload=null;this.rel='stylesheet'">
This helps reduce initial render-blocking caused by CSS files while still applying styles once each file has loaded.
What this module changes
- Replaces the default
SilverStripe\View\Requirements_Backendvia Injector. - Overrides
includeInHTML()inToast\Injectors\ToastEnhancedBackend. - Keeps JavaScript and custom head tags injection behavior aligned with the parent backend flow.
- Converts CSS requirements to
rel="preload"links with anonloadswitch torel="stylesheet".
Configured in _config/config.yml:
SilverStripe\Core\Injector\Injector: SilverStripe\View\Requirements_Backend: class: Toast\Injectors\ToastEnhancedBackend
Installation
composer require toastnz/deferred-css
Then flush configuration:
vendor/bin/sake dev/build flush=all
How it works
In ToastEnhancedBackend::includeInHTML():
- Checks if
</head>exists and there are requirements to inject. - Runs
processCombinedFiles()to preserve combined assets behavior. - Outputs JavaScript includes and inline custom scripts.
- Rewrites CSS includes as preload links with
as="style"andonloadrel swap. - Injects CSS/head tags into
<head>and scripts according to Silverstripe settings.
Notes
- This module targets Silverstripe Framework 6.
onload-based deferred CSS is widely used, but always test critical rendering paths in your project.- Validate frontend behavior in older browsers used by your audience.
License
BSD-3-Clause. See LICENSE.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-06-11