toastnz/deferred-css 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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_Backend via Injector.
  • Overrides includeInHTML() in Toast\Injectors\ToastEnhancedBackend.
  • Keeps JavaScript and custom head tags injection behavior aligned with the parent backend flow.
  • Converts CSS requirements to rel="preload" links with an onload switch to rel="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():

  1. Checks if </head> exists and there are requirements to inject.
  2. Runs processCombinedFiles() to preserve combined assets behavior.
  3. Outputs JavaScript includes and inline custom scripts.
  4. Rewrites CSS includes as preload links with as="style" and onload rel swap.
  5. 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-06-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固